Can you open an iOS app from an HTTP url scheme?
Asked Answered
H

4

11

I would like to open my iOS application similar to how it can be done on Android, that is by using a specific web address instead of a custom URL protocol.

This is how it works on Android. The Reddit is Fun app is a great example of this:

  • User is in their mail app, browser app, or something equivalent.
  • User clicks on a link to a reddit post. For this example, the link is "http://reddit.com/r/example"
  • Reddit is Fun app is setup to handle "http://reddit.com/" links
  • Android displays a dialog giving the user these options:
    • Open link in Web Browser
    • Open link in Reddit is Fun

I've been trying to find reference material on the Apple iOS URL Schemes, but everything I have found so far indicates that you need to have a custom URL protocol, and that you cannot use http://. You would have to use something like 'reddit://'.

The great thing about specifying an actual web address as a URL scheme is that if you didn't have the Reddit is Fun app, the browser would automatically open the page and that would be a great fallback. In the case of using a custom URL protocol like in iOS, if your device does not have the app installed, there is no fallback. There is no indication that it failed. There is no indication that it tried to do anything.

Does anyone know a way to open an application this way? For example, is it possible to open a reddit app when clicking on a 'http://reddit.com/' link?

Edit: What I find very interesting is that iOS already supports this to some extent with YouTube links.

Edit: It looks like there's no way to do exactly what I want on iOS. However, this post has some good suggestions on what to do. I was hoping things would have changed since 2009.

Heartbreak answered 19/9, 2014 at 14:35 Comment(1)
Use a custome url-scheme. And on your redirecting page use a timeout handler to redirect the user to the web version. Not perfect, but close.Acropolis
W
8

This is now enabled on ios in what they're calling "Universal Links": https://developer.apple.com/library/ios/documentation/General/Conceptual/AppSearch/UniversalLinks.html

There is a Cordova plugin to support this if your source is html based: https://github.com/nordnet/cordova-universal-links-plugin#android-web-integration

Worldling answered 24/12, 2015 at 20:43 Comment(0)
G
2

What you've found is correct, it can only be done with a custom scheme.

Gonidium answered 19/9, 2014 at 15:8 Comment(0)
S
2

Let me tell you how on iOS it is achieved by most apps I hope 'Reddit is Fun' too.

The Http link redirects you to a webpage which checks whether your iOS app is installed, by calling custom URL associated with your app.

If it returns failure the web page is loaded, otherwise the application is launched with specific view.

I hope that is what you were looking for.

Seismo answered 19/9, 2014 at 15:55 Comment(2)
Android handles things differently than iOS. You can actually specify a web address as your custom URL. This is especially important for Reddit is Fun, because it's a 3rd party app and they have no way to embed javascript into pages on reddit. The Android device just detects the user is visiting a reddit.com web page, looks in its registered apps and finds that an app can handle that URL, so it gives the user the option to pick which app they would like to proceed with. It's a brilliant system, and I'm disappointed that iOS doesn't have a similar system.Heartbreak
I would like to think that it is because iOS is more closed system compared to android and considers privacy more than sharing. It makes some sense when you see the overall approach where sharing between apps is limited. Anyways the debate will continue between user ease and openness or more controlled and secure.Seismo
S
1

You can actually do this, but it will require you to host a page on your server for every reddit article you want to link to. We built a dynamic version of this ourselves at Branch so that we don't have to manually create a page each time, and we also detect iOS versus Android. But for manually creating a page, are the steps:

If you want to send an email linking to http://reddit.com/r/example, you need to create a page and host it on your server (e.g. http://yourapp.com/hosted-links/r/example). It should look like this:

<!DOCTYPE html>
<html>
    <body>
        <script type="text/javascript">
            window.onload = function() {
                // Deep link to your app goes here
                document.getElementById("l").src = "reddit://r/example";

                setTimeout(function() {
                    // Link to the App Store should go here -- only fires if deep link fails                
                    window.location = "http://reddit.com/r/example";
                }, 500);
            };
        </script>
        <iframe id="l" width="1" height="1" style="visibility:hidden"></iframe>
    </body>
</html>

Now you can link to your server, http://yourapp.com/hosted-links/r/example, and it will open appropriately on iOS whether the user has the app or not.

School answered 24/2, 2015 at 21:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.