Browse Source

Merge pull request #436 from djorkaeffalexandre/sync.app-group

Create sync method to App Group dir
Travis Nuttall 5 years ago
parent
commit
d1732464f0
No account linked to committer's email address
2 changed files with 26 additions and 0 deletions
  1. 14
    0
      fs.js
  2. 12
    0
      ios/RNFetchBlob/RNFetchBlob.m

+ 14
- 0
fs.js View File

135
   return RNFetchBlob.pathForAppGroup(groupName)
135
   return RNFetchBlob.pathForAppGroup(groupName)
136
 }
136
 }
137
 
137
 
138
+/**
139
+ * Returns the path for the app group synchronous.
140
+ * @param  {string} groupName Name of app group
141
+ * @return {string} Path of App Group dir
142
+ */
143
+function syncPathAppGroup(groupName: string): string {
144
+  if (Platform.OS === 'ios') {
145
+    return RNFetchBlob.syncPathAppGroup(groupName);
146
+  } else {
147
+    return '';
148
+  }
149
+}
150
+
138
 /**
151
 /**
139
  * Wrapper method of readStream.
152
  * Wrapper method of readStream.
140
  * @param  {string} path Path of the file.
153
  * @param  {string} path Path of the file.
402
   writeFile,
415
   writeFile,
403
   appendFile,
416
   appendFile,
404
   pathForAppGroup,
417
   pathForAppGroup,
418
+  syncPathAppGroup,
405
   readFile,
419
   readFile,
406
   hash,
420
   hash,
407
   exists,
421
   exists,

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

233
     }
233
     }
234
 }
234
 }
235
 
235
 
236
+#pragma mark - fs.syncPathAppGroup
237
+RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(syncPathAppGroup:(NSString *)groupName) {
238
+    NSURL *pathUrl = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:groupName];
239
+    NSString *path = [pathUrl path];
240
+
241
+    if(path) {
242
+        return path;
243
+    } else {
244
+        return @"";
245
+    }
246
+}
247
+
236
 #pragma mark - fs.exists
248
 #pragma mark - fs.exists
237
 RCT_EXPORT_METHOD(exists:(NSString *)path callback:(RCTResponseSenderBlock)callback) {
249
 RCT_EXPORT_METHOD(exists:(NSString *)path callback:(RCTResponseSenderBlock)callback) {
238
     [RNFetchBlobFS exists:path callback:callback];
250
     [RNFetchBlobFS exists:path callback:callback];