如何以编程方式检查并打开iOS 8中的现有应用程序?

Ama*_*ain 11 ios swift

我想检查我的iphone中是否有应用程序.如果它存在,我想启动它,否则打​​开应用程序的App Store链接.

请建议所需的参数以及实现方法.

我有App Store链接打开应用程序,但我需要检查手机中是否已有应用程序.

Mem*_*had 13

试试这段代码

迅捷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")!)

    }

}
Run Code Online (Sandbox Code Playgroud)

迅捷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")!)
    }

}
Run Code Online (Sandbox Code Playgroud)


Nir*_*att 4

要从另一个应用程序内部打开一个应用程序,您需要从要打开的应用程序公开一个 URL 方案。

openURL如果可以使用函数(使用公开的自定义 URL 方案)打开应用程序,则用户可以直接访问您的应用程序。

如果没有,您可以使用该openURL功能打开应用程序商店应用程序页面,并提供 itunes 应用程序 URL。

这里有关于如何实现它的完整想法。