Skip to content

Instantly share code, notes, and snippets.

@FokkeZB
Created September 19, 2014 07:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FokkeZB/256db9e3c822eb31379a to your computer and use it in GitHub Desktop.
Save FokkeZB/256db9e3c822eb31379a to your computer and use it in GitHub Desktop.
Test URL schemes
<?
$scheme = isset($_GET['scheme']) ? $_GET['scheme'] : 'twitter';
$path = isset($_GET['path']) ? $_GET['path'] : '/';
$id = isset($_GET['id']) ? $_GET['id'] : 333903271;
$package = isset($_GET['scheme']) ? $_GET['scheme'] : 'com.twitter.android';
$auto = isset($_GET['auto']);
// Detection
$HTTP_USER_AGENT = strtolower($_SERVER['HTTP_USER_AGENT']);
$android = (bool) strpos($HTTP_USER_AGENT, 'android');
$iphone = !$android && ((bool) strpos($HTTP_USER_AGENT, 'iphone') || (bool) strpos($HTTP_USER_AGENT, 'ipod'));
$ipad = !$android && !$iphone && (bool) strpos($HTTP_USER_AGENT, 'ipad');
$ios = $iphone || $ipad;
$mobile = $android || $ios;
// Install
$ios_install = 'http://itunes.apple.com/app/id' . $id;
$android_install = 'http://play.google.com/store/apps/details?id=' . $package;
// Open
if ($ios) {
$open = $scheme . ':/' . $path;
}
if ($android) {
$open = 'intent:/' . $path . '#Intent;package=' . $package . ';scheme=' . $scheme . ';launchFlags=268435456;end;';
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>URL Schemes</title>
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<? if ($ios): ?>
<meta name="apple-itunes-app" content="app-id=<?= $id ?>, app-argument=<?= $open ?>"/>
<? endif ?>
</head>
<body>
<script>
function open() {
window.location = '<?= $open ?>';
<? if ($ios): ?>
setTimeout(function() {
if (!document.webkitHidden) {
window.location = '<?= $ios_install ?>';
}
}, 25);
<? endif ?>
}
</script>
<? if ($mobile): ?>
<? if ($ios): ?>
<p>Click the banner on top of this screen to <a href="<?= $ios_install ?>">install</a> our app or directly <a href="<?= $open ?>">open</a> this content in our app if you have it installed already.</p>
<? elseif ($android): ?>
<p>Go ahead and <a href="<?= $android_install ?>">install</a> our app or directly <a href="<?= $open ?>">open</a> this content in our app if you have it installed already.<p>
<? endif ?>
<? if ($auto): ?>
<script>open();</script>
<? endif ?>
<? else: ?>
<p>Go to the <a href="<?= $ios_install ?>">App Store</a> or <a href="<?= $android_install ?>">Google Play</a> to install and open this content in our app.</p>
<? endif ?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment