Browse Source

Fix potential problem when IOS documentController is not executed from main thread #168

Ben Hsieh 8 years ago
parent
commit
762c46e79a
1 changed files with 6 additions and 2 deletions
  1. 6
    2
      src/ios/RNFetchBlob/RNFetchBlob.m

+ 6
- 2
src/ios/RNFetchBlob/RNFetchBlob.m View File

446
     UIViewController *rootCtrl = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
446
     UIViewController *rootCtrl = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
447
     documentController.delegate = self;
447
     documentController.delegate = self;
448
     if(scheme == nil || [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:scheme]]) {
448
     if(scheme == nil || [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:scheme]]) {
449
-        [documentController  presentOptionsMenuFromRect:rootCtrl.view.bounds inView:rootCtrl.view animated:YES];
449
+        dispatch_sync(dispatch_get_main_queue(), ^{
450
+            [documentController  presentOptionsMenuFromRect:rootCtrl.view.bounds inView:rootCtrl.view animated:YES];
451
+        });
450
         resolve(@[[NSNull null]]);
452
         resolve(@[[NSNull null]]);
451
     } else {
453
     } else {
452
         reject(@"RNFetchBlob could not open document", @"scheme is not supported", nil);
454
         reject(@"RNFetchBlob could not open document", @"scheme is not supported", nil);
463
     documentController.delegate = self;
465
     documentController.delegate = self;
464
     
466
     
465
     if(scheme == nil || [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:scheme]]) {
467
     if(scheme == nil || [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:scheme]]) {
466
-        [documentController presentPreviewAnimated:YES];
468
+        dispatch_sync(dispatch_get_main_queue(), ^{
469
+            [documentController presentPreviewAnimated:YES];
470
+        });
467
         resolve(@[[NSNull null]]);
471
         resolve(@[[NSNull null]]);
468
     } else {
472
     } else {
469
         reject(@"RNFetchBlob could not open document", @"scheme is not supported", nil);
473
         reject(@"RNFetchBlob could not open document", @"scheme is not supported", nil);