11

I want to create a promotional link for my app - which i can distribute via email. When the user clicks on the link from the email, a webpage does this:

  1. Determines which OS (iOS or Android)
  2. If app installed on device - opens the app
  3. Else - takes user to AppStore (or) PlayStore (or) a custom URL.

I tried using the AppLinks (applinks.org) - but I am unable to get it to work. How does the browser understand the "al:xx:xxx.." tags ? Does it only work for facebook/twitter?

<html>
    <head>
       <meta property="al:ios:url" content="applinks://docs" />
       <meta property="al:ios:app_store_id" content="12345" />
       <meta property="al:ios:app_name" content="App Links" />
       <meta property="al:android:url" content="applinks://docs" />
       <meta property="al:android:app_name" content="App Links" />
       <meta property="al:android:package" content="org.applinks" />
       <meta property="al:web:url" content="http://applinks.org/documentation" />
   </head>

I also tried some javascript from another post - but if the app is not installed the browser shows an error:

<script>
    window.onload = function() {
        window.location = 'http://www.launchMyApp';

        setTimeout("window.location = 'http://play.google.com/someApp';", 1000);
    }
</script>

Please help with this. Thanks.

Sushanth --
  • 55,259
  • 9
  • 66
  • 105
vepe
  • 111
  • 1
  • 3
  • App Links doesn't solve the problem for you since Safari and Chrome don't have support for it. Also, while there are some JS solutions out there, none are ideal because they will all have some quirks. – Ming Li Feb 24 '15 at 21:43
  • I allso having same problem , Is there any possible sollutions to do thiis without scripts, any examples will be appreciated – Arun_SE Jun 18 '15 at 05:15
  • Javascript redirection certainly has potential quirks! I work at a company (hokolinks.com) and we did a much more complex script and it still fails for some crazy Android phones. Both Google and Apple announced a seamless solution (no JS needed) for this, using a file on the server for easy integration. Check universal links for iOS and App Link (yes, the same name) for Android. – rikas Jun 22 '15 at 22:59
  • I have a detailed solution document as answer here: https://stackoverflow.com/questions/46266797/deeplink-solution-for-ios-and-android-apps-works-in-facebook – Mustafa Atalar Sep 17 '17 at 18:17
  • I have written a detailed solution document under this question: https://stackoverflow.com/questions/46266797/deeplink-solution-for-ios-and-android-apps-works-in-facebook – Mustafa Atalar Sep 17 '17 at 18:20

3 Answers3

5

This is now possible in iOS 9. Apple announced Universal deep links this year in WWDC 2015. You may want to watch the video - Seamless Linking to Your App.

It can now:

  1. Check if app installed and open the content in iOS app
  2. Else fails gracefully and can open the content in safari.

One of the best feature of iOS 9 after Search API's.

Vlad Papko
  • 13,184
  • 4
  • 41
  • 57
mojo_
  • 301
  • 1
  • 3
  • 7
  • Thank you for posting the link regarding the Universal links approach. But for now i would like to go ahead with the approach that @IntrepidPat has suggested. – Sushanth -- Jun 29 '15 at 22:38
4
al:xx:xx:xx

What they gave you is a URI (See This SO post for the differences between URIs, URNs, and URLs. When your app is installed it can register itself to respond to a certain URL-scheme. Here's an example Spotify URI that links to a song.

spotify:track:0FutrWIUM5Mg3434asiwkp

If you have Spotify installed on your device (desktop included), you can click this link and it should open the Spotify app automatically. The app responds because it has registered itself as a responder to that type of URL. The rest of the URI is used by the app in order to perform some specific action(s). In this case, Spotify recognizes the URI as a link to a song with a specific track identifier, and opens the appropriate screen.

Your app could register itself to respond to a specific URL-scheme, and if a user taps on that link with the app installed, it would open directly to your app. The downside is that if the app isn't installed, the OS won't understand the URL-scheme, and throw an error.

The solution I think you're looking for would be a simple HTTP link to a page (script) that's hosted on your site. You could pass in parameters just as you would a normal link

http://www.myapp.org/?user=123&source=email. 

Your page would employ some server-side Javascript that would attempt to open the URL-scheme that's specified by your app -- Similar to what you have posted above. If that fails, it would then redirect the user to the appropriate app store based on the browser information in the HTTP User-Agent header. You might need some other Javascript to suppress the alerts.

Community
  • 1
  • 1
Pat Butkiewicz
  • 663
  • 5
  • 9
  • Thank you for the response. I am looking for a more complete solution as the App Links docs have been referring to the same implementation that you have presented. – Sushanth -- Jun 23 '15 at 05:05
  • When you say complete solution, do you mean you want all the code necessary for this to work? I don't think you'll find that here. – Pat Butkiewicz Jun 23 '15 at 14:06
  • Not really.. I am not looking for the complete code and I am sure no one will be getting as such here. What I meant is what you have suggested has already been implemented. i.e the IOS scheme has already been created and opens the App when you enter the URI directly in the browser.. But I am unable to do the same from the web page as such.. What I am trying to say is the solution that you have posted does not fully solve the puzzle. – Sushanth -- Jun 23 '15 at 18:12
  • Which part does it not solve? Sending the user to a regular HTTP page, which then uses javascript to figure out the platform, and redirects the user to the appropriate store, or opens the app (whichever is available) is what my answer is describing. This post: http://stackoverflow.com/questions/10237031/how-to-open-a-native-ios-app-from-a-web-app/10237577 is describing the javascript piece, and is exactly what you're trying to do using the same strategy. – Pat Butkiewicz Jun 23 '15 at 18:54
  • I was checking to see if it is possible to avoid adding javascript at all and use the Meta tags, which would open the link in the App, as I believe the Meta tags content will be followed when the hostname followed by the url maps to it. – Sushanth -- Jun 23 '15 at 20:53
  • Thank you for your answer. Looks like the approach that you suggested works with a bit of tweaking that goes in with it. – Sushanth -- Jun 29 '15 at 22:39
1

I was working on this for Facebook and found the following was generated by their system when you have them host the app links page for you.

<html>
<head><title>App Link</title>
    <meta property="fb:app_id" content="XXXXXXXXXXXXXXX"/>
    <meta property="al:ios:url" content="example://test"/>
    <meta property="al:ios:app_name" content="Example App"/>
    <meta property="al:ios:app_store_id" content="XXXXXXXXX"/>
    <meta property="al:android:package" content="com.example.client"/>
    <meta property="al:android:app_name" content="Example App"/>
    <meta property="al:android:url" content="example://test"/>
    <meta property="al:web:should_fallback" content="false"/>
    <meta http-equiv="refresh" content="0;url=http://play.google.com/store/apps/details?id=com.example.client"/>
</head>
<body>Redirecting...</body>
</html>

You can see the http-equiv meta tag at the bottom that does the redirect without any javascript and is supported on all major browsers.

mpkuth
  • 6,994
  • 2
  • 27
  • 44