Jan 14

We all know about the feature to register a custom URL scheme in Info.plist so that when Safari tries to open myapp://some?parameters, your app will be launched. This is very useful, but has it’s clear limitations.

Today I downloaded Apple’s new MobileMe Gallery app. At one point the app asked me if I wanted to always open MobileMe galleries in the app, instead of showing the web version. When I said “sure”, the app launched Safari which greeted me with a page that exclaimed: “Safari is now configured to use the MobileMe Gallery app.”

The result of this magic trick is that now when I go to a URL like this: http://gallery.me.com/something/000000, Safari launches the MobileMe Gallery app.

This is different from the custom URL scheme registration we all know and love:

  • A new URL scheme was not registered, it uses http:
  • Not all URLs starting with http: were taken over, just those associated with MobileMe galleries.
  • The registration was done dynamically.
  • I had a say in if I wanted this to happen or not.
  • It seems to rely on some undocumented feature in Mobile Safari.

Why would this be useful in your own apps?

  • On a web page you can create a link that will launch your app on the device if it has been installed. If the app is not installed you can display a web page that entices the user to purchase the app from the App Store.
  • Say you have a news reader app and you share a link to a news story with a friend via email. If your friend also has the app installed then the news story can display nicely in the app. If not, then Safari will be launched and your friend will see the web version of the news story.

With custom URL schemes both of the above scenarios would require two different links and force the user to select the right one based on their situation. Tap the wrong link and you’ll get an error message. Not pretty.

Apple, can you please document and expose this functionality to us mere mortals?
Update: Turns out that this feature does not rely on any private API:s. Read Brian’s comment below to learn how it’s done.

written by Nick \\ tags:

6 Responses to “Register URLs in Mobile Safari Dynamically?”

  1. Matthew Frederick Says:

    The mid-stream registration is cool, and indeed would be great to have access to. One http URL that’s already registered by default is maps.google.com, which sends you to the Maps app.

  2. Brian Tunning Says:

    This feature is built using all off-the-shelf APIs. When the device follows the gallery.me.com URL, and the web server detects a cookie set earlier, the web site redirects to a custom protocol registered in the plist (gallery://).

    This is done because it is not known if the recipient of a tell a friend email will be viewing the mail on an iPhone with the Gallery app installed, or a desktop machine.

  3. Nick Says:

    @Brian: Thank you for the insights! I didn’t realize that cookies in Mobile Safari were that persistent. But that makes sense. Just to test it, I deleted my cookies in Settings, and lo and behold, the MobileMe galleries now display in Safari again. Time to bring our server team into the loop so that we can add this cool feature to our apps.

  4. Dominic Tancredi Says:

    Awesome feature! We’ve added custom protocols to our app ComicVille. So when a user clicks on the link from their safari, it loads the app and creates a new webcomic link.

    But the difficulty has been figuring out how to register the protocol somewhere if a user doesn’t have the app yet… But if it involves a cookie being set and url redirect…

    So the url actually opens to a page, and the server detects if the browser is an iPhone, if it is, redirect to the custom protocol?

  5. Nick Says:

    @Dominic: The server detects if it’s an iPhone and if the iPhone has the cookie set that indicates that the app is installed on the device. If both conditions are true, then the server redirects to the custom protocol.

  6. Bobby Beckmann Says:

    I’ve been trying to get something like this working for quite awhile where the user is shown a webpage, and if they don’t have the app installed, it entices them to load it. The big difference in my approach is that I wanted it to work even when there was no network connection. I’ve got quite a javascript hack that does it. If you want to see what I mean, on your iphone, go to http://localb.net/gohorns and you’ll go through the “install” process, which installs a webclip on your phone that when launched will try to start the app, and if it fails will ask you to go to itunes to download the app. It isn’t perfect, and the UI leaves quite a bit to be desired, but the concept is good enough to get the point across.

    I’d love any feedback on the approach!

Leave a Reply