美文网首页
WKWebView JS端alert 不显示

WKWebView JS端alert 不显示

作者: 一步步漫漫走 | 来源:发表于2018-01-31 09:55 被阅读0次

    /** 针对JS端alert弹窗不显示 */

    - (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler{

        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];

    }

    /** 针对JS端alert弹窗不显示 */

    - (void)webView:(WKWebView *)webView runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL))completionHandler{

        //    DLOG(@"msg = %@ frmae = %@",message,frame);

        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:message?:@"" preferredStyle:UIAlertControllerStyleAlert];

        [alertController addAction:([UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {

            completionHandler(NO);

        }])];

        [alertController addAction:([UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

            completionHandler(YES);

        }])];

        [self presentViewController:alertController animated:YES completion:nil];

    }

    /** 针对JS端alert弹窗不显示 */

    - (void)webView:(WKWebView *)webView runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)defaultText initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(NSString * _Nullable))completionHandler{

        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:prompt message:@"" preferredStyle:UIAlertControllerStyleAlert];

        [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {

            textField.text = defaultText;

        }];

        [alertController addAction:([UIAlertAction actionWithTitle:@"完成" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

            completionHandler(alertController.textFields[0].text?:@"");

        }])];

        [self presentViewController:alertController animated:YES completion:nil];

    }

    相关文章

      网友评论

          本文标题:WKWebView JS端alert 不显示

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