@@ -487,6 +487,9 @@ + (BOOL)requiresMainQueueSetup
487
487
params.readTimeout = readTimeout;
488
488
NSNumber * backgroundTimeout = options[@" backgroundTimeout" ];
489
489
params.backgroundTimeout = backgroundTimeout;
490
+ bool hasBeginCallback = [options[@" hasBeginCallback" ] boolValue ];
491
+ bool hasProgressCallback = [options[@" hasProgressCallback" ] boolValue ];
492
+ bool hasResumableCallback = [options[@" hasResumableCallback" ] boolValue ];
490
493
491
494
__block BOOL callbackFired = NO ;
492
495
@@ -514,26 +517,32 @@ + (BOOL)requiresMainQueueSetup
514
517
return [self reject: reject withError: error];
515
518
};
516
519
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
+ }
524
529
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) {
533
541
params.resumableCallback = ^() {
534
542
if (self.bridge != nil )
535
543
[self sendEventWithName: @" DownloadResumable" body: nil ];
536
544
};
545
+ }
537
546
538
547
if (!self.downloaders ) self.downloaders = [[NSMutableDictionary alloc ] init ];
539
548
@@ -560,7 +569,7 @@ + (BOOL)requiresMainQueueSetup
560
569
RCT_EXPORT_METHOD (resumeDownload:(nonnull NSNumber *)jobId)
561
570
{
562
571
RNFSDownloader* downloader = [self .downloaders objectForKey: [jobId stringValue ]];
563
-
572
+
564
573
if (downloader != nil ) {
565
574
[downloader resumeDownload ];
566
575
}
@@ -572,7 +581,7 @@ + (BOOL)requiresMainQueueSetup
572
581
)
573
582
{
574
583
RNFSDownloader* downloader = [self .downloaders objectForKey: [jobId stringValue ]];
575
-
584
+
576
585
if (downloader != nil ) {
577
586
resolve ([NSNumber numberWithBool: [downloader isResumable ]]);
578
587
} else {
@@ -605,13 +614,14 @@ + (BOOL)requiresMainQueueSetup
605
614
params.toUrl = options[@" toUrl" ];
606
615
params.files = options[@" files" ];
607
616
params.binaryStreamOnly = [[options objectForKey: @" binaryStreamOnly" ] boolValue ];
608
-
609
617
NSDictionary * headers = options[@" headers" ];
610
618
NSDictionary * fields = options[@" fields" ];
611
619
NSString * method = options[@" method" ];
612
620
params.headers = headers;
613
621
params.fields = fields;
614
622
params.method = method;
623
+ bool hasBeginCallback = [options[@" hasBeginCallback" ] boolValue ];
624
+ bool hasProgressCallback = [options[@" hasProgressCallback" ] boolValue ];
615
625
616
626
params.completeCallback = ^(NSString * body, NSURLResponse *resp) {
617
627
[self .uploaders removeObjectForKey: [jobId stringValue ]];
@@ -630,19 +640,23 @@ + (BOOL)requiresMainQueueSetup
630
640
return [self reject: reject withError: error];
631
641
};
632
642
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
+ }
638
650
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
+ }
646
660
647
661
if (!self.uploaders ) self.uploaders = [[NSMutableDictionary alloc ] init ];
648
662
@@ -840,15 +854,15 @@ + (BOOL)requiresMainQueueSetup
840
854
// unused?
841
855
// __block NSURL* videoURL = [NSURL URLWithString:destination];
842
856
__block NSError *error = nil ;
843
-
857
+
844
858
PHFetchResult *phAssetFetchResult = [PHAsset fetchAssetsWithALAssetURLs: @[url] options: nil ];
845
859
PHAsset *phAsset = [phAssetFetchResult firstObject ];
846
-
860
+
847
861
PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc ] init ];
848
862
options.networkAccessAllowed = YES ;
849
863
options.version = PHVideoRequestOptionsVersionOriginal;
850
864
options.deliveryMode = PHVideoRequestOptionsDeliveryModeAutomatic;
851
-
865
+
852
866
dispatch_group_t group = dispatch_group_create ();
853
867
dispatch_group_enter (group);
854
868
0 commit comments