Skip to content

Commit

Permalink
Merge pull request #360 from jamesreggio/add-discretionary-flag
Browse files Browse the repository at this point in the history
Expose the iOS `discretionary` flag on `downloadFile`
  • Loading branch information
itinance authored Oct 6, 2017
2 parents 6e8b3e3 + e086d24 commit 1fcaa87
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions Downloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down
1 change: 1 addition & 0 deletions Downloader.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ - (void)downloadFile:(RNFSDownloadParams*)params
if (_params.background) {
NSString *uuid = [[NSUUID UUID] UUIDString];
config = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:uuid];
config.discretionary = _params.discretionary;
} else {
config = [NSURLSessionConfiguration defaultSessionConfiguration];
}
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,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;
Expand Down
2 changes: 2 additions & 0 deletions RNFSManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,8 @@ - (dispatch_queue_t)methodQueue
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;

Expand Down

0 comments on commit 1fcaa87

Please sign in to comment.