@@ -487,6 +487,9 @@ + (BOOL)requiresMainQueueSetup
487487 params.readTimeout = readTimeout;
488488 NSNumber * backgroundTimeout = options[@" backgroundTimeout" ];
489489 params.backgroundTimeout = backgroundTimeout;
490+ bool hasBeginCallback = [options[@" hasBeginCallback" ] boolValue ];
491+ bool hasProgressCallback = [options[@" hasProgressCallback" ] boolValue ];
492+ bool hasResumableCallback = [options[@" hasResumableCallback" ] boolValue ];
490493
491494 __block BOOL callbackFired = NO ;
492495
@@ -514,26 +517,32 @@ + (BOOL)requiresMainQueueSetup
514517 return [self reject: reject withError: error];
515518 };
516519
517- params.beginCallback = ^(NSNumber * statusCode, NSNumber * contentLength, NSDictionary * headers) {
518- if (self.bridge != nil )
519- [self sendEventWithName: @" DownloadBegin" body: @{@" jobId" : jobId,
520- @" statusCode" : statusCode,
521- @" contentLength" : contentLength,
522- @" headers" : headers ?: [NSNull null ]}];
523- };
520+ if (hasBeginCallback) {
521+ params.beginCallback = ^(NSNumber * statusCode, NSNumber * contentLength, NSDictionary * headers) {
522+ if (self.bridge != nil )
523+ [self sendEventWithName: @" DownloadBegin" body: @{@" jobId" : jobId,
524+ @" statusCode" : statusCode,
525+ @" contentLength" : contentLength,
526+ @" headers" : headers ?: [NSNull null ]}];
527+ };
528+ }
524529
525- params.progressCallback = ^(NSNumber * contentLength, NSNumber * bytesWritten) {
526- if (self.bridge != nil )
527- [self sendEventWithName: @" DownloadProgress"
528- body: @{@" jobId" : jobId,
529- @" contentLength" : contentLength,
530- @" bytesWritten" : bytesWritten}];
531- };
532-
530+ if (hasProgressCallback) {
531+ params.progressCallback = ^(NSNumber * contentLength, NSNumber * bytesWritten) {
532+ if (self.bridge != nil )
533+ [self sendEventWithName: @" DownloadProgress"
534+ body: @{@" jobId" : jobId,
535+ @" contentLength" : contentLength,
536+ @" bytesWritten" : bytesWritten}];
537+ };
538+ }
539+
540+ if (hasResumableCallback) {
533541 params.resumableCallback = ^() {
534542 if (self.bridge != nil )
535543 [self sendEventWithName: @" DownloadResumable" body: nil ];
536544 };
545+ }
537546
538547 if (!self.downloaders ) self.downloaders = [[NSMutableDictionary alloc ] init ];
539548
@@ -560,7 +569,7 @@ + (BOOL)requiresMainQueueSetup
560569RCT_EXPORT_METHOD (resumeDownload:(nonnull NSNumber *)jobId)
561570{
562571 RNFSDownloader* downloader = [self .downloaders objectForKey: [jobId stringValue ]];
563-
572+
564573 if (downloader != nil ) {
565574 [downloader resumeDownload ];
566575 }
@@ -572,7 +581,7 @@ + (BOOL)requiresMainQueueSetup
572581)
573582{
574583 RNFSDownloader* downloader = [self .downloaders objectForKey: [jobId stringValue ]];
575-
584+
576585 if (downloader != nil ) {
577586 resolve ([NSNumber numberWithBool: [downloader isResumable ]]);
578587 } else {
@@ -605,13 +614,14 @@ + (BOOL)requiresMainQueueSetup
605614 params.toUrl = options[@" toUrl" ];
606615 params.files = options[@" files" ];
607616 params.binaryStreamOnly = [[options objectForKey: @" binaryStreamOnly" ] boolValue ];
608-
609617 NSDictionary * headers = options[@" headers" ];
610618 NSDictionary * fields = options[@" fields" ];
611619 NSString * method = options[@" method" ];
612620 params.headers = headers;
613621 params.fields = fields;
614622 params.method = method;
623+ bool hasBeginCallback = [options[@" hasBeginCallback" ] boolValue ];
624+ bool hasProgressCallback = [options[@" hasProgressCallback" ] boolValue ];
615625
616626 params.completeCallback = ^(NSString * body, NSURLResponse *resp) {
617627 [self .uploaders removeObjectForKey: [jobId stringValue ]];
@@ -630,19 +640,23 @@ + (BOOL)requiresMainQueueSetup
630640 return [self reject: reject withError: error];
631641 };
632642
633- params.beginCallback = ^() {
634- if (self.bridge != nil )
635- [self sendEventWithName: @" UploadBegin"
636- body: @{@" jobId" : jobId}];
637- };
643+ if (hasBeginCallback) {
644+ params.beginCallback = ^() {
645+ if (self.bridge != nil )
646+ [self sendEventWithName: @" UploadBegin"
647+ body: @{@" jobId" : jobId}];
648+ };
649+ }
638650
639- params.progressCallback = ^(NSNumber * totalBytesExpectedToSend, NSNumber * totalBytesSent) {
640- if (self.bridge != nil )
641- [self sendEventWithName: @" UploadProgress"
642- body: @{@" jobId" : jobId,
643- @" totalBytesExpectedToSend" : totalBytesExpectedToSend,
644- @" totalBytesSent" : totalBytesSent}];
645- };
651+ if (hasProgressCallback) {
652+ params.progressCallback = ^(NSNumber * totalBytesExpectedToSend, NSNumber * totalBytesSent) {
653+ if (self.bridge != nil )
654+ [self sendEventWithName: @" UploadProgress"
655+ body: @{@" jobId" : jobId,
656+ @" totalBytesExpectedToSend" : totalBytesExpectedToSend,
657+ @" totalBytesSent" : totalBytesSent}];
658+ };
659+ }
646660
647661 if (!self.uploaders ) self.uploaders = [[NSMutableDictionary alloc ] init ];
648662
@@ -840,15 +854,15 @@ + (BOOL)requiresMainQueueSetup
840854 // unused?
841855 // __block NSURL* videoURL = [NSURL URLWithString:destination];
842856 __block NSError *error = nil ;
843-
857+
844858 PHFetchResult *phAssetFetchResult = [PHAsset fetchAssetsWithALAssetURLs: @[url] options: nil ];
845859 PHAsset *phAsset = [phAssetFetchResult firstObject ];
846-
860+
847861 PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc ] init ];
848862 options.networkAccessAllowed = YES ;
849863 options.version = PHVideoRequestOptionsVersionOriginal;
850864 options.deliveryMode = PHVideoRequestOptionsDeliveryModeAutomatic;
851-
865+
852866 dispatch_group_t group = dispatch_group_create ();
853867 dispatch_group_enter (group);
854868
0 commit comments