How to open ios app using url?

36,402

Solution 1

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.

Solution 2

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/

Share:
36,402

Related videos on Youtube

Vivek Sinha
Author by

Vivek Sinha

Sr. Android Developer, NightStay.in

Updated on July 20, 2020

Comments

  • Vivek Sinha
    Vivek Sinha almost 4 years

    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

  • Vivek Sinha
    Vivek Sinha about 8 years
    I have just a url in mailbox, using which I want to open app (if installed) or app store (if not )
  • USER_NAME
    USER_NAME over 6 years
    OP has asked to open url from browser not from his APP
  • Mitesh Dobareeya
    Mitesh Dobareeya almost 6 years
    any idea on how to handle redirecting the user from our browser to the App Store link ?
  • Alex Bauer
    Alex Bauer almost 6 years
    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
    Alex Bauer almost 6 years
    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.
  • Alberto Acuña
    Alberto Acuña almost 6 years
    can u write this for swift
  • Prakash
    Prakash almost 6 years
    How to avoid the open confirmation dialog?