我在 viewDidLoad
中有以下代码,它在 iOS 4.3 上正常工作,但在 iOS 5/5.1 上挂起.在 iOS 5/5.1 上,警告对话框显示但无法关闭,UI 线程冻结,无法单击 OK 按钮.
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 上挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!