Browse Source

Create sync method to App Group dir

Djorkaeff Alexandre 4 years ago
parent
commit
c98cff00b7
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

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