当使用GCD调用时,UIWebView stringByEvaluatingJavaScriptFromString在iOS5.0 / 5.1上挂起 [英] UIWebView stringByEvaluatingJavaScriptFromString hangs on iOS5.0/5.1 when called using GCD
本文介绍了当使用GCD调用时,UIWebView stringByEvaluatingJavaScriptFromString在iOS5.0 / 5.1上挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 viewDidLoad
中有以下代码,它在iOS 4.3上正常运行,但它挂在iOS 5 / 5.1上。在iOS 5 / 5.1上,显示警告对话框但无法解除,UI线程冻结,无法单击确定按钮。
I have the following code in viewDidLoad
, which works properly on iOS 4.3, but it hangs on iOS 5/5.1. On iOS 5/5.1, the alert dialog is shown but can not be dismissed, the UI thread freezes, the OK button just can not be clicked.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
dispatch_sync(dispatch_get_main_queue(), ^{
[self.webview stringByEvaluatingJavaScriptFromString:@"alert('HELLO WORLD!')"];
});
});
这是一个错误吗?
推荐答案
经过测试,我认为它是一个Bug,并且更改代码使用
After test, I consider it as a Bug, and changing code to use
[webView performSelectorOnMainThread:@selector(stringByEvaluatingJavaScriptFromString:) withObject:js waitUntilDone:NO]
将解决它。
这篇关于当使用GCD调用时,UIWebView stringByEvaluatingJavaScriptFromString在iOS5.0 / 5.1上挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文