1. 程式人生 > >iOS呼叫js的方法 alert不能點選的原因

iOS呼叫js的方法 alert不能點選的原因

The gist is that the thread handling the JS from the stringByEvaluatingJavaScriptFromString: method and the thread handling the iOS alert view are probably blocking each other, making the “Close” button unresponsive.
it might be better to have the UIWebView trigger an UIAlertView rather than rely on UIWebView to handle the JS alert. The workaround above would be suitable for most debugging purposes though.
關鍵點在於,使用StrugByEngutyActudiaJavaScript執行JS方法的執行緒和執行iOS彈框檢視的執行緒可能彼此阻塞,使得“關閉”按鈕無響應。
最好讓UIWebVIEW觸發一個alert檢視,而不是依賴於UIWebView來處理JS的alert。不過下面這種方式適用於大多數的除錯了
NSString *functionStr = [NSStringstringWithFormat:@”postAction(%zd)”,action];
NSString *funcScript =[NSString stringWithFormat:@”setTimeout(function(){%@;},1)”,functionStr];
[_context evaluateScript:funcScript];