【问题标题】:iOS WkWebView - What is the difference in this situation?iOS WkWebView - 这种情况有什么区别?
【发布时间】:2025-12-16 18:30:01
【问题描述】:

我有下面的源代码。

当 URL 方案有 tel、sms、item- 或 mailto 时,WkWebview 将打开应用程序。 (item 和 mailto 是我们的自定义方案)

我想知道使用decisionHandler(.cancle)和decisionHandler(.allow)有什么区别,因为在这两种情况下实现UIApplication.shared.open(URL)是一样的。

 if scheme == "tel" || scheme == "sms" || scheme == "itms-services" {
            UIApplication.shared.open(destinationUrl)
            decisionHandler(.allow)
            return
        }
        
        else if scheme == "mailto" {
            UIApplication.shared.open(URL(string: "ncsone://mail/write"))
            decisionHandler(.cancel)
            return
        }

【问题讨论】:

    标签: ios wkwebview


    【解决方案1】:

    正如WKNavigationDelegate 的官方文档中所述,将decisionHandler.cancel 值一起使用将阻止WKWebView 加载destinationUrl 的内容。

    这可能用于防止 web 视图导航到未知 URL。

    【讨论】: