Browse Source

added pathForAppGroup iOS function (#328)

Nick Pomfret 7 years ago
parent
commit
fc27abd3c6
4 changed files with 35 additions and 0 deletions
  1. 10
    0
      fs.js
  2. 14
    0
      ios/RNFetchBlob/RNFetchBlob.m
  3. 1
    0
      ios/RNFetchBlobFS.h
  4. 10
    0
      ios/RNFetchBlobFS.m

+ 10
- 0
fs.js View File

137
 
137
 
138
 }
138
 }
139
 
139
 
140
+/**
141
+ * Returns the path for the app group.
142
+ * @param  {string} groupName Name of app group
143
+ * @return {Promise}
144
+ */
145
+function pathForAppGroup(groupName:string):Promise {
146
+  return RNFetchBlob.pathForAppGroup(groupName);
147
+}
148
+
140
 /**
149
 /**
141
  * Wrapper method of readStream.
150
  * Wrapper method of readStream.
142
  * @param  {string} path Path of the file.
151
  * @param  {string} path Path of the file.
366
   writeStream,
375
   writeStream,
367
   writeFile,
376
   writeFile,
368
   appendFile,
377
   appendFile,
378
+  pathForAppGroup,
369
   readFile,
379
   readFile,
370
   exists,
380
   exists,
371
   createFile,
381
   createFile,

+ 14
- 0
ios/RNFetchBlob/RNFetchBlob.m View File

184
 
184
 
185
 }
185
 }
186
 
186
 
187
+#pragma mark - fs.pathForAppGroup
188
+RCT_EXPORT_METHOD(pathForAppGroup:(NSString *)groupName
189
+                  resolver:(RCTPromiseResolveBlock)resolve
190
+                  rejecter:(RCTPromiseRejectBlock)reject)
191
+{
192
+    NSString * path = [RNFetchBlobFS getPathForAppGroup:groupName];
193
+
194
+    if(path) {
195
+        resolve(path);
196
+    } else {
197
+        reject(@"RNFetchBlob file not found", @"could not find path for app group", nil);
198
+    }
199
+}
200
+
187
 #pragma mark - fs.exists
201
 #pragma mark - fs.exists
188
 RCT_EXPORT_METHOD(exists:(NSString *)path callback:(RCTResponseSenderBlock)callback) {
202
 RCT_EXPORT_METHOD(exists:(NSString *)path callback:(RCTResponseSenderBlock)callback) {
189
     [RNFetchBlobFS exists:path callback:callback];
203
     [RNFetchBlobFS exists:path callback:callback];

+ 1
- 0
ios/RNFetchBlobFS.h View File

52
 + (NSString *) getDocumentDir;
52
 + (NSString *) getDocumentDir;
53
 + (NSString *) getTempPath:(NSString*)taskId withExtension:(NSString *)ext;
53
 + (NSString *) getTempPath:(NSString*)taskId withExtension:(NSString *)ext;
54
 + (NSString *) getPathOfAsset:(NSString *)assetURI;
54
 + (NSString *) getPathOfAsset:(NSString *)assetURI;
55
++ (NSString *) getPathForAppGroup:(NSString *)groupName;
55
 + (void) getPathFromUri:(NSString *)uri completionHandler:(void(^)(NSString * path, ALAssetRepresentation *asset)) onComplete;
56
 + (void) getPathFromUri:(NSString *)uri completionHandler:(void(^)(NSString * path, ALAssetRepresentation *asset)) onComplete;
56
 
57
 
57
 // fs methods
58
 // fs methods

+ 10
- 0
ios/RNFetchBlobFS.m View File

129
     return tempPath;
129
     return tempPath;
130
 }
130
 }
131
 
131
 
132
++ (NSString *) getPathForAppGroup:(NSString *)groupName {
133
+    NSFileManager* fileManager = [NSFileManager defaultManager];
134
+    NSURL* containerURL = [fileManager containerURLForSecurityApplicationGroupIdentifier:groupName];
135
+    if(containerURL) {
136
+        return [containerURL path];
137
+    } else {
138
+        return nil;
139
+    }
140
+}
141
+
132
 #pragma margk - readStream
142
 #pragma margk - readStream
133
 
143
 
134
 + (void) readStream:(NSString *)uri
144
 + (void) readStream:(NSString *)uri