Create a link that either launches iOS app, or redirects to app store

Silromen picture Silromen · Jan 12, 2011 · Viewed 34.2k times · Source

Possible Duplicate:
Is it possible to register a http+domain-based URL Scheme for iPhone apps, like YouTube and Maps?

I have a custom URL scheme for my iOS app, and I want to be able to email a link to someone that will either launch the app if it's on the device, or take them to the app store if they don't have it.

I'd like to be able to send myapp://someurl and have that either launch or go to myapp on the appstore, but I don't think this will work out of the box.

Instead, I'm thinking of creating a link that loads some javascript which will try myapp://someurl, and if that fails will instead load the app store link.

My javascript knowledge is crappy. I can set window.location to perform the redirect, but there doesn't seem to be a way to catch errors from that in order to perform another action if that fails.

Anyone know how to do this?

Answer

David Vaccaro picture David Vaccaro · Dec 26, 2012
 window.launchsockPicker = function() {
       setTimeout(function() {
        window.location = 'http://myDomain.com/install-app.cfm'
       }, 500);

       window.location = 'myApp://?context=someVariableIfNeeded';
   };