0

I try to open an app from browser in iOS. I can do it by appending a certain keyword with schema. Now I would like to create a link, so that if that certain app is installed, it should open that app. If it's not installed, it should open the iTunes link.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Anupam Gupta
  • 623
  • 1
  • 7
  • 18
  • if you know the app URL scheme of app you want to open, you can just use open URL to open that app. – Teja Nandamuri Feb 21 '18 at 19:43
  • Yes I know that, and i can open that app, but in second case if that app is not get instal the in what manner I came to know that I need to open that app iTune url ? I can do only a single task at a time either I can open the iTune or I can open that app. – Anupam Gupta Feb 21 '18 at 19:47
  • you can only redirect the users if you know the App Store link of that app. Please go through https://stackoverflow.com/questions/433907/how-to-link-to-apps-on-the-app-store . If the app is not installed then openURL will return false. You can then redirect the user as suggested in the link. – Teja Nandamuri Feb 21 '18 at 19:50
  • Possible duplicate of [How to link to apps on the app store](https://stackoverflow.com/questions/433907/how-to-link-to-apps-on-the-app-store) – Teja Nandamuri Feb 21 '18 at 19:50
  • In my case it has some other scenario such as I would like to share a URL of app in other medium such as whats app etc not inside any app. If the app located at that url is already installed then it simply open that app otherwise that url open app store address. – Anupam Gupta Feb 21 '18 at 20:00
  • I can configure my browser code to open either the app using schema or I can open that url but I need to perform above task using that single url – Anupam Gupta Feb 21 '18 at 20:01
  • Possible duplicate of [How to check if an app is installed from a web-page on an iPhone?](https://stackoverflow.com/questions/13044805/how-to-check-if-an-app-is-installed-from-a-web-page-on-an-iphone) – theCoderGuy Feb 21 '18 at 20:14
  • You can look for Universal Links. – Larme Feb 21 '18 at 20:15
  • I tried to do so using universal link and able to open my app while accessing my url , but if app is not installed then what needs to be do.? It simply open my web inside the browser and i wants to open iTunes address of my app. – Anupam Gupta Feb 21 '18 at 20:20

1 Answers1

0

say you want to go to an app named "awesome"

func openApp() {
        let appHookUrl = URL(string: "awesome://")

        if UIApplication.shared.canOpenURL(appHookUrl!)
        {
            UIApplication.shared.open(appHookUrl!, options:[:]) { (success) in
                if !success {

                }
            }
        } else {
            // awesome is not installed, do whatever else.
        }
}

and you need to add the appHook in your info.plist:

<array>
        <string>awesome</string>
</array>
shayegh
  • 302
  • 1
  • 9