72

iTunes, App Store and YouTube on iOS clearly register http://... URL schemes to open their apps.

Can anyone do that, not just your own protocol?

The reason I want to do this is that I am working on an app for a festival. I want to "intercept" links to specific pages on the website and launch the app instead, if installed.

So far I have no had much luck

baswell
  • 776
  • 1
  • 6
  • 5

5 Answers5

61

The way you can do this for "http://" URLs (and what I think Apple and Spotify do) this is to:

  1. Register a custom URL scheme like the other answers have shown.

  2. Set up your HTTP URL to point to a real webpage.

  3. Put a script on that page to redirect to your custom URL if is on iOS.

For example, here is a sample page which will take you to the Twitter app for a particular user or the Twitter website depending upon if you are on the web or on your iOS device:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Twitter</title>
</head>
<body>
    <script type="text/javascript">
        var username = document.location.search.substr(1);
        document.location.replace(
            "standalone" in window.navigator ?
            'twitter:@'+username :              // iOS
            'http://twitter.com/'+username);    // others
    </script>
</body>
</html>

Try it out here: http://bl.ocks.org/d/3153819/?mckamey

Community
  • 1
  • 1
mckamey
  • 16,875
  • 15
  • 76
  • 114
  • 1
    Yes, that is what I am doing now. Not quite how the App Store does it though as it goes straight to the app store without going to Safari first. – baswell Jul 21 '12 at 04:47
  • If you view-source on an itunes page (e.g., http://itunes.com/apps/instagram) they have a script attached to body onload which if it detects it is running on iOS opens the same search but with an "itms://" URL. When you visit this with an iPhone, it will first bounce to the iTunes app, then to the AppStore app. So I think they employ a similar strategy just faster switching. – mckamey Jul 22 '12 at 18:12
  • 27
    what if your app is not installed? – stephane k. Jan 25 '13 at 14:46
  • @stephanek. see this comment and the next one - http://iosdevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html#comment-11194 – Shade Mar 13 '13 at 09:06
  • 3
    It might also be possible to use a hidden iFrame on the page pointed at the custom scheme. If it fails, no one notices anything. If it succeeds then it takes control away from the page to the app. – mckamey Mar 13 '13 at 16:16
  • How about now, in iOS 7? Does its custom scheme support http? Most web services have both an app and mobile web page, and generally prefer an app-first strategy. Android supports it with Intent filter, and iOS looks really backwards if it doesn't support that. – NeoWang Sep 23 '13 at 04:19
  • @NeoWang I believe if Apple were to allow it, *all* `http://` traffic would go to that registered app. While I'd love to be able to direct Chrome to be the recipient of this scheme, it seems that Apple doesn't want to allow that. – mckamey Sep 25 '13 at 19:32
  • 1
    @mckamey Yes, now I think Apple's way is better. User expects the browser to open with a http url, and iOS safari has smart banner allowing user to switch to app if it is installed. On the other hand, if http is allowed as app url, then a third-party app can hijack an official website, which is a secuirty hole to say the least. – NeoWang Sep 26 '13 at 09:40
  • 9
    @NeoWang Apple's way is not better. Android allows the scheme, host, path, and port to be defined, and I haven't heard of any problems with that. The user is always allowed to choose which app they want to open the url with so no hijacking would occur without the user being aware of it. Furthermore, in Android, if the user doesn't want the app to open it, the browser is guaranteed to be able to, making much more dynamic than iOS. – craned Apr 02 '15 at 20:10
  • Per @mckamey's suggestion about the hidden iframe, see a nice answer here: http://stackoverflow.com/questions/1108693/is-it-possible-to-register-a-httpdomain-based-url-scheme-for-iphone-apps-like/24133372#24133372 – roy650 May 12 '15 at 14:15
  • @mckamey, your answer is not up to date. The answer below is much more relevant. I think you should mention that. – Vsevolod Poletaev Aug 23 '17 at 16:23
  • Shocking that tech would change after several years! Perhaps the owner of the question should update selected answer. – mckamey Aug 23 '17 at 19:57
46

iOS 9 supports Universal Links, which allows iOS to launch an app based on a standard http:// URL (based on the hostname) without the user having to go through Safari.

It requires some web server configuration (you need a website), but once setup, the registered app will open the link instead of Safari.

For the users that don't have iOS 9, you can use Smart Banners to ease the experience.

Marcus Adams
  • 49,523
  • 8
  • 81
  • 132
4

Unfortunately I don't think you can do that. You can register your own custom scheme e.g yourFestival:// and pass data from the outside world (SMS , email , other apps) to your app.

I wrote a blog post about this here : Using custom schemes and passing data between iOS apps.

I hope this helps.

Marius Ciocanel
  • 151
  • 1
  • 6
2

No, you can only register custom schemes.

And I cannot see Apple doing this, either...

Eiko
  • 25,336
  • 14
  • 53
  • 69
  • Bummer. Apple certainly does it. Email (or SMS) yourself and iTunes store link (http://itunes....). Click on it in mail on the iPhone. The App Store opens, without going to Safari first. – baswell Dec 09 '10 at 23:31
  • No. For email, there is (obviously) the mailto: scheme, for sms it's sms:, and in case of iTunes I think they use ordinary http:, on the first call, but then redirect to something else (which can be done transparently so the user won't see it). – Eiko Dec 10 '10 at 08:48
  • @HappyFlow Not sure what you are trying to tell me? – Eiko Aug 20 '13 at 15:16
  • Doesn't that mean that you can't implement a web browser that would open when a url is clicked? – diidu Nov 03 '20 at 10:49
1

The question is old, but since I came across to this page now, years later, when searching for answer to the same question, I'll add answer on how to do it now:

Use Universal links. First enable "Associated Domains" or you App ID in developer.apple.com. Then add your domain as applink in Xcode (select Target->Signing & Capabilities->Associated Domains) and then create an apple-app-site-association file on your website.

Details are explained here.

diidu
  • 2,523
  • 14
  • 30