How to Programmatically check and open an existing app in iOS 8?

后端 未结 6 2116
执笔经年
执笔经年 2021-02-08 04:14

I want to check whether an app is present in my iphone or not. If it is present I want to launch it else open the App Store link of the app.

Please suggest the required

6条回答
  •  半阙折子戏
    2021-02-08 04:44

    try this code

    swift 2.2

     @IBAction func openInstaApp(sender: AnyObject) {
        var instagramHooks = "instagram://user?username=your_username"
        var instagramUrl = NSURL(string: instagramHooks)
        if UIApplication.sharedApplication().canOpenURL(instagramUrl!)
        {
            UIApplication.sharedApplication().openURL(instagramUrl!)
    
        } else {
            //redirect to safari because the user doesn't have Instagram
            println("App not installed")
            UIApplication.sharedApplication().openURL(NSURL(string: "https://itunes.apple.com/in/app/instagram/id389801252?m")!)
    
        }
    
    }
    

    swift 3

     @IBAction func openInstaApp(sender: AnyObject) {
        let instagramHooks = "instagram://user?username=your_username"
        let instagramUrl = URL(string: instagramHooks)
        if UIApplication.shared.canOpenURL(instagramUrl! as URL)
        {
            UIApplication.shared.open(instagramUrl!)
    
        } else {
            //redirect to safari because the user doesn't have Instagram
            print("App not installed")
            UIApplication.shared.open(URL(string: "https://itunes.apple.com/in/app/instagram/id389801252?m")!)
        }
    
    }
    

提交回复
热议问题