Browse Source

#229 add IOS API excludeFromBackupKey

Ben Hsieh 8 years ago
parent
commit
1b4f4bf871
4 changed files with 31 additions and 0 deletions
  1. 4
    0
      src/index.js
  2. 10
    0
      src/ios.js
  3. 16
    0
      src/ios/RNFetchBlob/RNFetchBlob.m
  4. 1
    0
      src/ios/RNFetchBlobFS.m

+ 4
- 0
src/index.js View File

@@ -217,6 +217,10 @@ function fetch(...args:any):Promise {
217 217
   let respInfo = {}
218 218
   let [method, url, headers, body] = [...args]
219 219
 
220
+  // # 241 normalize null or undefined headers, in case nil or null string
221
+  // pass to native context
222
+  headers = _.map(headers, (h) =>  h || '');
223
+
220 224
   // fetch from file system
221 225
   if(URIUtil.isFileURI(url)) {
222 226
     return fetchFile(options, method, url, headers, body)

+ 10
- 0
src/ios.js View File

@@ -37,6 +37,16 @@ function openDocument(path:string, scheme:string) {
37 37
     return Promise.reject('RNFetchBlob.previewDocument only supports IOS.')
38 38
 }
39 39
 
40
+/**
41
+ * Set excludeFromBackupKey to a URL to prevent the resource to be backuped to
42
+ * iCloud.
43
+ * @param  {string} url URL of the resource, only file URL is supported
44
+ * @return {Promise}
45
+ */
46
+function excludeFromBackupKey(url:string) {
47
+  return RNFetchBlob.excludeFromBackupKey('file://' + path);
48
+}
49
+
40 50
 export default {
41 51
   openDocument,
42 52
   previewDocument

+ 16
- 0
src/ios/RNFetchBlob/RNFetchBlob.m View File

@@ -472,6 +472,22 @@ RCT_EXPORT_METHOD(openDocument:(NSString*)uri scheme:(NSString *)scheme resolver
472 472
     }
473 473
 })
474 474
 
475
+# pragma mark - exclude from backup key
476
+
477
+RCT_EXPORT_METHOD(excludeFromBackupKey:(NSString *)url resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject
478
+{
479
+    NSError *error = nil;
480
+    [ [NSURL URLWithString:url] setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:&error];
481
+    if(!error)
482
+    {
483
+        resolve(@[[NSNull null]]);
484
+    } else {
485
+        reject(@"RNFetchBlob could not open document", [error description], nil);
486
+    }
487
+    
488
+})
489
+
490
+
475 491
 RCT_EXPORT_METHOD(df:(RCTResponseSenderBlock)callback
476 492
 {
477 493
     [RNFetchBlobFS df:callback];

+ 1
- 0
src/ios/RNFetchBlobFS.m View File

@@ -208,6 +208,7 @@ NSMutableDictionary *fileStreams = nil;
208 208
         
209 209
     }];
210 210
     
211
+    
211 212
 }
212 213
 
213 214
 // send read stream chunks via native event emitter