Expose the iOS discretionary flag on downloadFile

This commit is contained in:
James Reggio 2017-10-06 11:48:40 -04:00
parent 252cd5a3e5
commit e086d24549
4 changed files with 6 additions and 1 deletions

View File

@ -15,6 +15,7 @@ typedef void (^ProgressCallback)(NSNumber*, NSNumber*);
@property (copy) BeginCallback beginCallback; // Download has started (headers received)
@property (copy) ProgressCallback progressCallback; // Download is progressing
@property bool background; // Whether to continue download when app is in background
@property bool discretionary; // Whether the file may be downloaded at the OS's discretion (iOS only)
@property (copy) NSNumber* progressDivider;

View File

@ -45,6 +45,7 @@
if (_params.background) {
NSString *uuid = [[NSUUID UUID] UUIDString];
config = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:uuid];
config.discretionary = _params.discretionary;
} else {
config = [NSURLSessionConfiguration defaultSessionConfiguration];
}

View File

@ -486,7 +486,8 @@ type DownloadFileOptions = {
fromUrl: string; // URL to download file from
toFile: string; // Local filesystem path to save the file to
headers?: Headers; // An object of headers to be passed to the server
background?: boolean;
background?: boolean; // Continue the download in the background after the app terminates (iOS only)
discretionary?: boolean; // Allow the OS to control the timing and speed of the download to improve perceived performance (iOS only)
progressDivider?: number;
begin?: (res: DownloadBeginCallbackResult) => void;
progress?: (res: DownloadProgressCallbackResult) => void;

View File

@ -422,6 +422,8 @@ RCT_EXPORT_METHOD(downloadFile:(NSDictionary *)options
params.headers = headers;
NSNumber* background = options[@"background"];
params.background = [background boolValue];
NSNumber* discretionary = options[@"discretionary"];
params.discretionary = [discretionary boolValue];
NSNumber* progressDivider = options[@"progressDivider"];
params.progressDivider = progressDivider;