Skip to content

Instantly share code, notes, and snippets.

@mckamey
Created July 20, 2012 23:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mckamey/3153819 to your computer and use it in GitHub Desktop.
Save mckamey/3153819 to your computer and use it in GitHub Desktop.
Example iOS Custom URL Redirection

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.

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

<!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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment