Skip to content

Commit 1fcaa87

Browse files
authored
Merge pull request #360 from jamesreggio/add-discretionary-flag
Expose the iOS `discretionary` flag on `downloadFile`
2 parents 6e8b3e3 + e086d24 commit 1fcaa87

File tree

4 files changed

+6
-1
lines changed

4 files changed

+6
-1
lines changed

Downloader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ typedef void (^ProgressCallback)(NSNumber*, NSNumber*);
1515
@property (copy) BeginCallback beginCallback; // Download has started (headers received)
1616
@property (copy) ProgressCallback progressCallback; // Download is progressing
1717
@property bool background; // Whether to continue download when app is in background
18+
@property bool discretionary; // Whether the file may be downloaded at the OS's discretion (iOS only)
1819
@property (copy) NSNumber* progressDivider;
1920

2021

Downloader.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ - (void)downloadFile:(RNFSDownloadParams*)params
4545
if (_params.background) {
4646
NSString *uuid = [[NSUUID UUID] UUIDString];
4747
config = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:uuid];
48+
config.discretionary = _params.discretionary;
4849
} else {
4950
config = [NSURLSessionConfiguration defaultSessionConfiguration];
5051
}

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,8 @@ type DownloadFileOptions = {
496496
fromUrl: string; // URL to download file from
497497
toFile: string; // Local filesystem path to save the file to
498498
headers?: Headers; // An object of headers to be passed to the server
499-
background?: boolean;
499+
background?: boolean; // Continue the download in the background after the app terminates (iOS only)
500+
discretionary?: boolean; // Allow the OS to control the timing and speed of the download to improve perceived performance (iOS only)
500501
progressDivider?: number;
501502
begin?: (res: DownloadBeginCallbackResult) => void;
502503
progress?: (res: DownloadProgressCallbackResult) => void;

RNFSManager.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,8 @@ - (dispatch_queue_t)methodQueue
422422
params.headers = headers;
423423
NSNumber* background = options[@"background"];
424424
params.background = [background boolValue];
425+
NSNumber* discretionary = options[@"discretionary"];
426+
params.discretionary = [discretionary boolValue];
425427
NSNumber* progressDivider = options[@"progressDivider"];
426428
params.progressDivider = progressDivider;
427429

0 commit comments

Comments
 (0)