美文网首页
ios js 遇到的一些崩溃 2020-04-02

ios js 遇到的一些崩溃 2020-04-02

作者: iOS打怪升级 | 来源:发表于2020-04-02 15:09 被阅读0次

崩溃堆栈:was not called

0  CoreFoundation!__exceptionPreprocess + 0xdc
1  libobjc.A.dylib!objc_exception_throw + 0x34
2  CoreFoundation!+[NSException raise:format:] + 0x68
3  WebKit!WebKit::CompletionHandlerCallChecker::~CompletionHandlerCallChecker() + 0x8c


andle Exception:
04-01 10:46:51.353 [crashreportsdk]     Exception Name: NSInternalInconsistencyException
04-01 10:46:51.353 [crashreportsdk]     Exception Reason: Completion handler passed to -[CustomWkWebViewController webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:] was not called

#pragma mark - WKUIDelegate
//! alert(message)
- (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler
{
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:message preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        completionHandler();
    }];
    [alertController addAction:cancelAction];
    UIViewController * currentVC = [HQTabBarRootViewController currentWidowsViewController];
     
    [self presentViewController:alertController animated:YES completion:nil];
}

//! confirm(message)
- (void)webView:(WKWebView *)webView runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL))completionHandler
{
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:message preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        completionHandler(NO);
    }];
    UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        completionHandler(YES);
    }];
    [alertController addAction:cancelAction];
    [alertController addAction:confirmAction];
    [self presentViewController:alertController animated:YES completion:nil];
}

//! prompt(prompt, defaultText)
- (void)webView:(WKWebView *)webView runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)defaultText initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(NSString *))completionHandler
{
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:prompt message:nil preferredStyle:UIAlertControllerStyleAlert];
    [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
        textField.placeholder = defaultText;
    }];
    UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        completionHandler(alertController.textFields[0].text);
    }];
    [alertController addAction:confirmAction];
    [self presentViewController:alertController animated:YES completion:nil];
}

说明: [self presentViewController:alertController animated:YES completion:nil];
这里的present 的时候需要判断一下,否则可能会导致崩溃 runJavaScriptAlert 等代理方法显示 not called ,比如当前代码执行的时候,已经有一个alert 弹窗在显示了,此时你的present 就不会成功,那么该代理方法最终就不会有completionHandler 的调用,那么就会崩溃提示没有调用该代理方法
解决方法就是判断用当前的顶级控制器去present alert , 而不是简单的self

html 脚本参考:会触发ios 里面的WKUIDelegate 代理调用


    function alert_func()
    {
        window.alert("alert test hahah")
    }

    function confirm_func()
    {
        window.confirm("confirm ok")
    }

    function prompt_func()
    {
        window.prompt("prompt_func ok","请输入文本")
    }

有用的参考

相关文章

  • ios js 遇到的一些崩溃 2020-04-02

    崩溃堆栈:was not called 说明: [self presentViewController:alert...

  • 腾讯bugly上传符号表小记

    需求来源 项目中使用腾讯bugly来记录崩溃日志,熟悉iOS的同学都知道,有时候遇到的一些崩溃日志并不够清晰,所以...

  • iOS崩溃调试

    iOS崩溃调试 iOS崩溃调试

  • iOS 符号化闪退日志

    iOS分析崩溃日志 二 iOS应用崩溃日志分析 iOS崩溃crash大解析

  • js in iOS References

    PPT地址:js in iOS Dev iOS开发中常用到与js交互的技术,本文总结一些这方面的参考资料: iOS...

  • 查看iOS崩溃日志

    iOS开发经常会遇到崩溃的情况,许多上架的应用也会经常出现崩溃的情况,今天就来总结一下如何查看iOS奔溃日志。 先...

  • iOS崩溃crash解析--dSYM使用

    写在前面这个是使用dSYM遇到的一些坑,具体的dSYM原理等请参看iOS崩溃crash大解析 开车了 最近我们 a...

  • iOS通过线上崩溃日志(不是友盟的日志)定位到崩溃位置

    通常我们在iOS开发中,会遇到很多闪退崩溃的问题,当我们在本地调试的时候,大部分崩溃xcode可以直接定位到崩溃的...

  • iOS Crash统计

    在iOS开发中,不免会遇到程序的崩溃,有些崩溃可在调试状态下捕获并解决,有些崩溃却在发布版本后出现,现在我们可用X...

  • iOS捕获崩溃异常

    在开发中经常会遇到崩溃的情况,在调试过程中可以直接看到崩溃信息,但是发布之后查看崩溃信息就比较困难了。iOS提供了...

网友评论

      本文标题:ios js 遇到的一些崩溃 2020-04-02

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