zoukankan      html  css  js  c++  java
  • WKWebView无法(通过URL schemes)跳转到其他App

    Custom scheme URL 在WKWebView中默认是不支持的 (但Safari可以).

    我们可以通过NSError来进行一些处理从而使得程序可以正常跳转:

    func webView(webView: WKWebView, didFailNavigation navigation: WKNavigation!, withError error: NSError) {
        handleError(error)
    }
    
    func webView(webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: NSError) {
        handleError(error)
    }
    
    func handleError(error: NSError) {
        if let failingUrl = error.userInfo["NSErrorFailingURLStringKey"] as? String {
            if let url = NSURL(string: failingUrl) {
                let didOpen = UIApplication.sharedApplication().openURL(url)
                if didOpen {
                    print("openURL succeeded")
                    return
                }
            }
        }
    }
    

    Note: 在iOS9中,如果你要想使用canOpenURL, 你必须添加URL schemes到Info.plist中的白名单, 否则一样跳转不了...

  • 相关阅读:
    ReactJs入门
    Studio-Class Diagram
    Visual Studio-Sequence Diagram
    架构、职责、数据一致性
    Microsoft Build 2015
    Net下无敌的ORM
    SpringMVC1
    插件式Web框架
    ASP.NET的CMS
    Android Drawable绘图学习笔记(转)
  • 原文地址:https://www.cnblogs.com/Rinpe/p/5897306.html
Copyright © 2011-2022 走看看