瀏覽代碼

added pathForAppGroup iOS function (#328)

Nick Pomfret 7 年之前
父節點
當前提交
fc27abd3c6
共有 4 個文件被更改,包括 35 次插入0 次删除
  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 查看文件

@@ -137,6 +137,15 @@ function mkdir(path:string):Promise {
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 150
  * Wrapper method of readStream.
142 151
  * @param  {string} path Path of the file.
@@ -366,6 +375,7 @@ export default {
366 375
   writeStream,
367 376
   writeFile,
368 377
   appendFile,
378
+  pathForAppGroup,
369 379
   readFile,
370 380
   exists,
371 381
   createFile,

+ 14
- 0
ios/RNFetchBlob/RNFetchBlob.m 查看文件

@@ -184,6 +184,20 @@ RCT_EXPORT_METHOD(createFileASCII:(NSString *)path data:(NSArray *)dataArray cal
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 201
 #pragma mark - fs.exists
188 202
 RCT_EXPORT_METHOD(exists:(NSString *)path callback:(RCTResponseSenderBlock)callback) {
189 203
     [RNFetchBlobFS exists:path callback:callback];

+ 1
- 0
ios/RNFetchBlobFS.h 查看文件

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

+ 10
- 0
ios/RNFetchBlobFS.m 查看文件

@@ -129,6 +129,16 @@ NSMutableDictionary *fileStreams = nil;
129 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 142
 #pragma margk - readStream
133 143
 
134 144
 + (void) readStream:(NSString *)uri