It is necessary to synchronously execute a line of code on the main thread.
webView = [[UIWebView alloc] initWithFrame:CGRectZero];
If synchronously from the main thread go to the main thread, there will be a deadlock
.
check
if (dispatch_get_current_queue() == dispatch_get_main_queue())
perfect, but dispatch_get_current_queue
forbidden, what can replace it in iOS7
?
- (NSString *)getMyString { NSString *myString; __block UIWebView *webView; if (dispatch_get_current_queue() == dispatch_get_main_queue()) { webView = [[UIWebView alloc] initWithFrame:CGRectZero]; } else { dispatch_sync(dispatch_get_main_queue(), ^{ webView = [[UIWebView alloc] initWithFrame:CGRectZero]; }); } myString = [webView stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"]; return myString; }
dispatch_sync
in the same thread from which it is called.dispatch_async
works flawlessly, but it does not fit - Alexey Alybin