如何以编程方式检查并打开iOS 8中的现有应用程序? [英] How to Programmatically check and open an existing app in iOS 8?

查看:140
本文介绍了如何以编程方式检查并打开iOS 8中的现有应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 parameters to do so and way to implement it.

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

I have the App Store link to open the app but I need to check if app is already present in the phone.

推荐答案

试试此代码

swift 2.2

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

}

这篇关于如何以编程方式检查并打开iOS 8中的现有应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆