WKWebView监控异步请求的确认框

- (void)webView:(WKWebView *)webView runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL result))completionHandler{
    UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"提示" message:message preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *cancelAction = [UIAlertAction
                                   actionWithTitle:@"取消"
                                   style:UIAlertActionStyleCancel
                                   handler:^(UIAlertAction *action)
                                   {
                                       completionHandler(NO);
                                   }];
    
    UIAlertAction *okAction = [UIAlertAction
                               actionWithTitle:@"确定"
                               style:UIAlertActionStyleDefault
                               handler:^(UIAlertAction *action)
                               {
                                   completionHandler(YES);
                               }];
    
    [alert addAction:cancelAction];
    [alert addAction:okAction];
    //弹出提示框;
    [webView.viewController presentViewController:alert animated:true completion:nil];
}

 

posted on 2017-02-04 16:04  程序“猿”  阅读(469)  评论(0)    收藏  举报

导航