简体   繁体   中英

Fail with checking if an app is installed iOS

I have already read about UIApplication.shared.canOpenURL . But in my case it somehow doesn't work. I have a scheme:

在此处输入图片说明

If I have VK app installed, the url vk:// works, and Safari successfully asks me if I want to open this app. On this step, canOpenURL returns true .

If the app is not installed, Safari says, that the url is invalid. But canOpenURL still returns true .

What's going on? Does canOpenURL check only syntax of the URL? Then how must I check if the app is installed?

For open app from deep linking you should also write some lines of code for schema and 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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM