美文网首页
ios wkwebView中点击弹框崩溃

ios wkwebView中点击弹框崩溃

作者: 老夫撩发少年狂 | 来源:发表于2018-01-29 14:17 被阅读542次

项目中的网页在弹出弹框时,点击操作直接崩溃,发现是网页服务器端用js的方法调用alert时,往往格式不符合iphone要求,这时可捕捉到该alert,在手机端自己调用。

#pragma mark alert弹出框

- (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler {
    UIAlertAction *alertActionCancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        // 返回用户选择的信息
        completionHandler();
    }];
    UIAlertAction *alertActionOK = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        completionHandler();
    }];
    // alert弹出框
    WSAlertViewController *alterVC =[WSAlertViewController alertControllerWithTitle:message message:nil preferredStyle:UIAlertControllerStyleAlert];
    [alterVC addAction:alertActionCancel];
    [alterVC addAction:alertActionOK];
    [self presentViewController:alterVC animated:YES completion:nil];
}

当然除了alert之外,其他的Confirm选择框、TextInput输入框等都可以通过代理方法捕获后用自定义的方法实现相应的效果。

相关文章

网友评论

      本文标题:ios wkwebView中点击弹框崩溃

      本文链接:https://www.haomeiwen.com/subject/chvibxtx.html