3

Is there any way to test if an iOS can handle a custom URL scheme? I have an app that registered a custom url scheme to be able to open the app from a hyperlink in mobile safari. How ever, I'd like to tell the user they need to go to the appstore to download the app if they dont have it installed.

Is there a clever way to test a URL and catch when it fails and the reason for it to fail?

David Rönnqvist
  • 56,267
  • 18
  • 167
  • 205
Johan Nordberg
  • 3,621
  • 4
  • 33
  • 58

1 Answers1

7

This is the best I can come up with, but it's only tested in iOS 5:

If your link in mobile safari is <a href="myapp://path">link text</a>, change it to: <a href="http://mydomain.com/launchapp?location=path">link text</a>, then at the top of the /launchapp page, put a hidden iframe with the desired URL: <iframe src="myapp://path" style="display:none"></iframe>. In the body of the page, put your message about needing to go to the appstore to download the app.

If the user has the app: They will not see the launchapp page, they will be directed seemlessly to the app url. If the user does not have the app: They will get a nasty alert about 'The URL could not be loaded', click OK, then they will be looking at your 'you need to download the app' page.

Update - March 2013

Check out this comment on a related SO answer. Apparently, if your app isn't already installed, you can seamlessly redirect to your app in the App Store using an approach like this (not tested):

// setup fallback (redirect to App Store)
var start = (new Date()).valueOf();
setTimeout(function() {
    var end = (new Date()).valueOf();

    // prevent App Store redirect upon returning to safari from myapp
    if (end - start > 1000) return;

    // get a seamless redirect if you use itms://... instead of http://itunes.com/...
    window.location = 'itms://my/app/URI';
}, 25);

// Attempt to load my custom url scheme
window.location = 'myapp://my/path'
Community
  • 1
  • 1
colllin
  • 9,442
  • 9
  • 49
  • 65
  • Thanks for the trick. Is there any way to get rid of the annoying safari popup ? – Diwann Feb 27 '13 at 16:14
  • Not sure, maybe there is with iOS 6. That's the caveat with this method ;) but at least they know what's wrong after they dismiss the popup and read your page. – colllin Feb 28 '13 at 01:57
  • I will try with the new smart-app-banner. it seems to send data (app-argument). http://developer.apple.com/library/ios/#documentation/AppleApplications/Reference/SafariWebContent/PromotingAppswithAppBanners/PromotingAppswithAppBanners.html – Diwann Feb 28 '13 at 10:48
  • 1
    well, it's working fine, but you can't determine how it is shown to the user. If it has been disclosed once, it will never show up again... I will instead try the proposal in this thread : http://stackoverflow.com/questions/1108693/is-it-possible-to-register-a-httpdomain-based-url-scheme-for-iphone-apps-like – Diwann Feb 28 '13 at 11:11
  • yes, good link, especially [this comment](http://stackoverflow.com/questions/1108693/is-it-possible-to-register-a-httpdomain-based-url-scheme-for-iphone-apps-like?lq=1#comment-2369319) and the comment right below that one. I'll update my answer with that info. – colllin Mar 01 '13 at 17:48