Last active
March 14, 2016 08:03
-
-
Save phynet/161e63bfad3dff5318b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Example: needed to save a pdf document and show that pdf data in main thread. So using the example: | |
*/ | |
dispatch_async(dispatch_get_global_queue(0, 0), ^{ | |
//load your data here. | |
dispatch_async(dispatch_get_main_queue(), ^{ | |
//update UI in main thread. | |
}); | |
}); | |
/* | |
* I ended using this code: | |
*/ | |
//Thread save | |
__block NSURL *url = nil; | |
dispatch_async(dispatch_get_global_queue(0, 0), ^{ | |
//load data here. | |
[self savePDF:myData withDocumentName:documentName onComplete:^(NSURL *urlDocument){ | |
url = urlDocument; | |
}]; | |
dispatch_async(dispatch_get_main_queue(), ^{ | |
//update UI in main thread. | |
[self presentPdfReaderViewController:url withBlock:^(BOOL success, NSDictionary *dict) { | |
success ? [self setSendResultWithBoolean:success messageError:dict[SUCCESS] command:command] : [self setSendResultWithBoolean:success messageError:dict[ERROR] command:command]; | |
}]; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment