Skip to content

Commit e086d24

Browse files
committed
Expose the iOS discretionary flag on downloadFile
1 parent 252cd5a commit e086d24

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