Skip to content
This repository was archived by the owner on Mar 16, 2019. It is now read-only.

Commit 762c46e

Browse files
committed
Fix potential problem when IOS documentController is not executed from main thread #168
1 parent b133597 commit 762c46e

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/ios/RNFetchBlob/RNFetchBlob.m

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,9 @@ - (NSDictionary *)constantsToExport
446446
UIViewController *rootCtrl = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
447447
documentController.delegate = self;
448448
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+
});
450452
resolve(@[[NSNull null]]);
451453
} else {
452454
reject(@"RNFetchBlob could not open document", @"scheme is not supported", nil);
@@ -463,7 +465,9 @@ - (NSDictionary *)constantsToExport
463465
documentController.delegate = self;
464466

465467
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+
});
467471
resolve(@[[NSNull null]]);
468472
} else {
469473
reject(@"RNFetchBlob could not open document", @"scheme is not supported", nil);

0 commit comments

Comments
 (0)