3
我使用GCD在UIWebView中運行javascript,當它是正常的javascipt時,一切似乎都找到了,但是當涉及到「alert」時,彈出式模式視圖會使我的用戶界面變得無法響應。stringByEvaluatingJavaScriptFromString:使我的用戶界面變得無響應
這裏是我在UIWebViewDelegate方法中的代碼。
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSLog(@"RECEIVED");
BOOL re =[WebParserStrategy shouldConsiderAsRequest:request];
NSLog(@"--receive Request: %@ jumpTo:%@", request.URL.absoluteString, re == YES ? @"YES" : @"NO!!");
if(re == NO)
{
dispatch_async(parserRequestToMessageQueue, ^{
NSString *msg;
NSDictionary *param;
[WebParserStrategy transferRequest:request toMessage:&msg withParam:¶m];
WebObserverChain *chain = [self.messageObservers objectForKey:msg];
if(chain == nil)
;//NSLog(@"!!!unknow message:%@ not found in message list", msg);
else {
dispatch_async(dispatch_get_main_queue(), ^{
[self.webView stringByEvaluatingJavaScriptFromString:@"alert('')"];
});
}
});
}
return re;}
所以,我想我必須做所有的工作沒有GCD,爲了確保警報JavaScript將正常工作,是嗎?我很困惑調用[self.webView stringByEvaluatingJavaScriptFromString:@「alert('')」];直接把它放到dispatch_get_main_queue()中,畢竟這個方法是在主線程上調用的,是嗎? – 2012-08-04 01:28:44