WKWebView在js使用alert方法调用弹框的时候导致线程卡死,显示弹框的方法有问题!
#65 问题所在地方,AXWebViewController.m文件 755行 以下是我处理方法:
-
(void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler { // Get host name of url. NSString host = webView.URL.host; // Init the alert view controller. // UIAlertController alert = [UIAlertController alertControllerWithTitle:host?:@"来自网页的消息" message:message preferredStyle: UIAlertControllerStyleAlert]; // Init the cancel action. // UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:NULL]; // Init the ok action. // UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { // [alert dismissViewControllerAnimated:YES completion:NULL]; // completionHandler(); // }]; // Add actions. // [alert addAction:cancelAction]; // [alert addAction:okAction];
/** 使用您上方的写法,弹框弹不出来还会线程卡死,多点几次弹alert的方法会卡死项目 */ UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:message?:@"" preferredStyle:UIAlertControllerStyleAlert]; [alertController addAction:([UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { completionHandler(); }])]; [self presentViewController:alertController animated:YES completion:nil]; }
@LHWen 方便提一个PR吗?
不好意思,今天才看到您的消息,我已经写了demo放在我的GitHub上,地址是:https://github.com/LHWen/TestAXWebViewControllerAlert.git