142
140

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

iOS/Androidのブラウザ開いた時に、URLスキームが存在すればアプリ・存在しなければマーケットを開く方法

Last updated at Posted at 2014-03-10

Androidだとそれ用の書き方があるからいいんだけど、iOSだとJSでやるしかなさげ。

Androidの場合

"intent://hoge.com#Intent;scheme=get-hoge;package=com.hoge.activity;end"

iOSの場合

<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="utf-8">
  <title>iOSで開いた時に、URLスキームが存在すればアプリを開く、存在しなければAppStoreを開く</title>

  <script type="text/javascript">
    $(function(){
      var userAgent = navigator.userAgent.toLowerCase();
      if (userAgent.search(/iphone|ipad|ipod/) > -1) {
        // Launch myapp via URL scheme
        launch_frame.location.href= "myapp://";

        setTimeout(function(){
          // Open App DL page in iTunes Store
          location.href= "itmss://itunes.apple.com/us/app/myapp/id99999999?ls=1&mt=8";
        } , 500);
      }
    });
  </script>
</head> 
<body>
  <div style="width:0; height:0; overflow:hidden;">
  <iframe id="launch_frame" name="launch_frame">
  </iframe>
  </div>
</body> 
</html>
142
140
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
142
140

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?