48

What I want to do is, We have having one product info on Website. That product is available on store. what we have on website is that, Product info and one button for that product.

I want to take two actions on that button. When User opens website on iPad or iPhone on Safari (browser) and click on GetProduct button, then following two actions must be taken place. 1. If user is already having product installed on device then directly open the app in device. 2. If user is not having the app on device then link user to the app on store, so he can download from there.

I already handled second condition, but how to handle the first condition. If I am already having the app then how to open it on action of button click in browser.

7
  • 1
    check out how to create URL Schemas in iOS and use them.
    – devluv
    Sep 17, 2014 at 5:48
  • @sagar how did you handle the condition where if the user does not have the app then it opens in the app store?
    – Brian Risk
    Jul 13, 2017 at 17:51
  • @BrianRisk :- You just have to add the URL of the app which is on store into the section URLScema -> URL. That will automatically check if App is present in device then open it automatically, if not then it will redirect to the AppStore URL
    – Sagar
    Aug 2, 2017 at 9:14
  • @Sagar Can you please tell which URL schema you are referring to when you are redirecting to the app store URL? Jun 19, 2018 at 11:56
  • @Mr.Ratnadeep :- You need to use URL schema along with : and // like this (e.g., "myScheme://") make sure this is case sensitive. Then it will check for app in device not found then it will redirect to iTunes and then match with team id and opens the app on store.
    – Sagar
    Jun 20, 2018 at 13:16

2 Answers 2

68

You can achieve what you're asking for by using a URL scheme. This will enable you to call the openUrl: method with your application's url scheme which will then launch your app. Here's how you setup a custom url scheme:

  1. Open your app's Info.plist and add a row with a key called URL Types.
  2. Expand the URL Types item, and Item 0 under it and you'll see URL Identifier
  3. Enter your app's bundle identifier (e.g. com.myCompany.myApp) as the URL Identifier value.
  4. Add another row to Item 0 and enter URL Schemes.
  5. Expand the URL Schemes and under Item 0 type in the name for your custom scheme (e.g. myScheme).

You should now be able to open your app from Safari by typing myScheme:// in the address bar. Alternatively, from your app, you can launch the other app like this:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"myScheme://"]];

Note that you can also send parameters to the app you're launching with the url scheme (more on that here).

7
  • Hi GAD, thanks for the comment. I will do this. thanks for help
    – Sagar
    Sep 17, 2014 at 6:10
  • Hi GAD, I tried with your way. I added these fields. my URL schema is TestApp. then I go to Browser and type ://TestApp in address bar the phone didn't open the app. But app was already in device. Is I am doing anything wrong while typing it in address bar.
    – Sagar
    Sep 17, 2014 at 6:42
  • You need to type TestApp:// is that what you typed?
    – Gad
    Sep 17, 2014 at 9:40
  • 2
    Thanks, this works beautifully and is just what I needed. By the way, I have found that the URL Scheme name (e.g., "myScheme://") is case-insensitive, at least on my iPad Mini A1432 running iOS 8.3. Jun 12, 2015 at 14:30
  • 1
    The URL works fine on Safari but not with Chrome or any other browsers.. Does anyone know how to do it with other browsers too.??? Aug 17, 2015 at 7:11
13

With iOS9 Apple introduced a way to open installed app from Links. Here is the official link for this : Apple universal links

2
  • 2
    It's worth noting that Universal Links will not open with a link from the same domain. So for example say you're on example.com/page-1, if you click a link to example.com/page-2 you will not be able to get the app to open via Universal Links.
    – Jack
    Jun 24, 2020 at 16:28
  • 1
    @Jack Then how would you do it then: Launching your app with the same domain as the webpage you are on? Is there something like an intent: launch point as with Android? May 19, 2023 at 0:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.