我已经阅读了有关 UIApplication.shared.canOpenURL
的内容。但就我而言,它以某种方式不起作用。我有一个方案:
如果我安装了 VK app
,则 url vk://
有效,Safari 会成功询问我是否要打开此应用程序。在此步骤中,canOpenURL
返回 true
。
如果应用程序未安装,Safari 会提示 url 无效。但是 canOpenURL
仍然返回 true
。
这是怎么回事? canOpenURL
是否只检查 URL 的语法?那我该如何查看是否安装了应用呢?
最佳答案
对于通过深度链接打开的应用程序,您还应该为架构和 URL::编写一些代码行
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
if(url.absoluteString == "appname://app/https://appurl"){
let defaults = NSUserDefaults.standardUserDefaults()
if defaults.objectForKey("access_token") != nil {
// check condition what you want for open specific page
}
else{
let loginVC: LoginViewController = mainStoryboard.instantiateViewControllerWithIdentifier("LoginViewController") as! LoginViewController
self.window?.rootViewController = loginVC
}
}
self.window?.makeKeyAndVisible()
关于ios - 检查应用程序是否安装失败 iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45073936/