Skip to content

Instantly share code, notes, and snippets.

@phynet
Last active March 14, 2016 08:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phynet/161e63bfad3dff5318b7 to your computer and use it in GitHub Desktop.
Save phynet/161e63bfad3dff5318b7 to your computer and use it in GitHub Desktop.
/*
* 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