22

I want to open my ios app using URL schemes. I am able to open app using this. But I want if app is not installed then app store should be opened where user can download app. Is this possible? How can I do that?

EDIT Explaining question step wise:

  1. I have a mail in my inbox with a url.
  2. I click on URL then i. If app is installed in phone, app will launch. ii. Otherwise app store will be opened to download app.

Thank

seenukarthi
  • 8,241
  • 10
  • 47
  • 68
Vivek Sinha
  • 1,556
  • 1
  • 13
  • 24
  • Check the answer see if it help@Vivek Sinha – Ronak Chaniyara Mar 08 '16 at 12:27
  • 1
    there is already an answer to that, please see this answer here: http://stackoverflow.com/a/3808757/1447518 – Idan Mar 08 '16 at 12:33
  • 3
    Possible duplicate of [Detecting programmatically whether an app is installed on iPhone](http://stackoverflow.com/questions/3808691/detecting-programmatically-whether-an-app-is-installed-on-iphone) – dr0i Mar 08 '16 at 12:45
  • I want to open it from a url not from any other app. Above link is not what I want. – Vivek Sinha Mar 08 '16 at 12:50
  • You may find tutorial here https://medium.com/@abhimuralidharan/universal-links-in-ios-79c4ee038272 – SHS Feb 16 '19 at 09:26

3 Answers3

7

I handled it via my server side code:

if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
location.replace("com.myapp://");
setTimeout(function() {
                if (!document.webkitHidden) {
                    location.replace("https://itunes.apple.com/app/xxxxxxxx");
                }
            }, 25);}
else if ((navigator.userAgent.match(/android/i)) || (navigator.userAgent.match(/Android/i))) {
location.replace("https://play.google.com/store/apps/details?id=packagename&hl=en");}
else  {
location.replace("http://www.example.com");}

I put this in my www.mysite.com/download page & share this url via campaigns.

Vivek Sinha
  • 1,556
  • 1
  • 13
  • 24
5

What you're describing is called Deferred Deep Linking (Deep Linking refers to using a link to open your app, even directly to a specific piece of content, and Deferred means that it works even if the app isn't installed first).

Unfortunately there's no native way to accomplish this yet on either iOS or Android. URL schemes don't work, because they always fail if the app isn't installed. Apple's new Universal Links in iOS 9 get closer, but you'd still have to handle redirecting the user from your website to the App Store

A free service like Branch.io (full disclosure: they're so awesome I work with them) can handle all of this for you though. Here's the docs page covering exactly how to create email links like you described: https://dev.branch.io/features/email-campaigns/overview/

Alex Bauer
  • 13,147
  • 1
  • 27
  • 44
  • any idea on how to handle redirecting the user from our browser to the App Store link ? – Mitesh Dobareeya Jun 06 '18 at 14:31
  • By 'our browser', do you mean Safari? If so, you just redirect to the App Store URL (Javascript or HTTP 3XX) and the App Store will open. – Alex Bauer Jun 06 '18 at 15:42
  • In theory, it should work in any browser with support for custom URI schemes...which should be all of them on iOS. I've never seen one where this didn't work, but I suppose it's possible. – Alex Bauer Jun 07 '18 at 14:34
-1

If your App is not installed in device then, you can open app store using below lines of code:

NSString *iTunesUrlofApp = @"itms://itunes.apple.com/us/app/apple-store/...";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesUrlofApp]];

Try below code:

if([[UIApplication sharedApplication] canOpenURL:url]){
    // Means your app is installed, and it can be open
    [[UIApplication sharedApplication] openURL:url];
}
else{
    //Your app is not installed so, Open app store with your apps iTunes Url
    NSString *iTunesUrlofApp = @"itms://itunes.apple.com/us/app/apple-store/...";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesUrlofApp]];

}

After iOS 5 you can also use https:// to avoid redirections.

Edit:

Check the link to open app from url if installed: Universal links to open app from Url.

Ronak Chaniyara
  • 5,335
  • 3
  • 24
  • 51