iOS笔记之URL Schemes

270 阅读1分钟

1.URL Schemes:实现App之间的跳转,以及通过网页实现跳转到对应的App内。
2.配置 Url Schemes

  • 给自己的App注册URL Schemes
    打开Xcode工程,在Info.plist的URL Types添加一个新的URL Schemes。需要填入Identifier和URL Schemes;示例:URL Schemes:example Identifier:com.example.www.
  • 测试URL Schemes
    先安装App,在浏览器中输入example://,如果弹出提示框,是否访问该应用说明配置成功。
  • 代码跳转到第三方应用时需要在info.plist中添加Queried URL Schemes,将第三方的URL Schemes添加进去,限制个数为50
        let url = URL(string: "example://")

        if UIApplication.shared.canOpenURL(url) {

            if #available(iOS 10.0, *) {

                UIApplication.shared.open(url, options: [:], completionHandler: nil)

            } else {

                UIApplication.shared.openURL(url)

            }

        }