-2

I want to check whether an app is installed in my phone or not. If it is already installed I want to launch the same. If it not installed I need to open the Appstore link.

I could opened the Appstore from the url,

https://itunes.apple.com/us/app/stack-ar/id1269638287?mt=8

by using the below code,

let urlString = "https://itunes.apple.com/us/app/stack-ar/id1269638287?mt=8"
UIApplication.shared.open(URL(string: urlString)!, options: [:]) { (success) in

        }

How can I open the app if it is installed?

Vineesh TP
  • 7,755
  • 12
  • 66
  • 130

2 Answers2

3

To open another App from your App the target App needs to implement a URL Scheme. Some Apps document their URL Schemes while others don't. You may need to ask the Developer of the Target App or check the Info.plist file.

If an app does not implement a URL Scheme, there is no way of starting it (that I know of).

If it does implement an URL Scheme, you need to whitelist that scheme in your app. You do that by adding LSApplicationQueriesSchemes to your Info.plist like shown here:

enter image description here

The image shows the whitelisting of the URL Schemes corresponding with Facebook and Twitter. Adapt this for the app that you want to open.

Once you have done that, you can use UIApplication.sharedApplication().canOpenURL(...) to check if the app is installed and UIApplication.sharedApplication().openURL(...) to open the target app.

I'd also like to suggest using SKStoreProductViewController to show the app in the App Store instead of opening Safari. This way it is possible to present an App Store like view directly in your App without leaving it.

naglerrr
  • 2,809
  • 1
  • 12
  • 24
2

Use Url schemes to open third party application.

var profile = "instagram://user?username=johndoe"
var instagramUrl = NSURL(string: profile)

if UIApplication.sharedApplication().canOpenURL(instagramUrl!) {  
    UIApplication.sharedApplication().openURL(instagramUrl!)

} else {
    //redirect to safari because the user doesn't have Instagram
    UIApplication.sharedApplication().openURL(NSURL(string: "http://instagram.com/")!)
}
Kathiresan Murugan
  • 2,783
  • 3
  • 23
  • 44