Skip to content
This repository was archived by the owner on Mar 16, 2019. It is now read-only.

Commit 1b4f4bf

Browse files
committed
#229 add IOS API excludeFromBackupKey
1 parent ae1bdbc commit 1b4f4bf

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

src/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ function fetch(...args:any):Promise {
217217
let respInfo = {}
218218
let [method, url, headers, body] = [...args]
219219

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+
220224
// fetch from file system
221225
if(URIUtil.isFileURI(url)) {
222226
return fetchFile(options, method, url, headers, body)

src/ios.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ function openDocument(path:string, scheme:string) {
3737
return Promise.reject('RNFetchBlob.previewDocument only supports IOS.')
3838
}
3939

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+
4050
export default {
4151
openDocument,
4252
previewDocument

src/ios/RNFetchBlob/RNFetchBlob.m

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,22 @@ - (NSDictionary *)constantsToExport
472472
}
473473
})
474474

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+
475491
RCT_EXPORT_METHOD(df:(RCTResponseSenderBlock)callback
476492
{
477493
[RNFetchBlobFS df:callback];

src/ios/RNFetchBlobFS.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ + (void) readStream:(NSString *)uri
208208

209209
}];
210210

211+
211212
}
212213

213214
// send read stream chunks via native event emitter

0 commit comments

Comments
 (0)