Redirect to application if installed, otherwise to App Store

后端 未结 8 2529
渐次进展
渐次进展 2020-12-02 04:52

I know it\'s possible to link directly to an app in iOS by registering a custom scheme (e.g. so://) and it\'s also possible to link to the app in the appstore via itunes.

8条回答
  •  粉色の甜心
    2020-12-02 05:10

    I think the more simple answer would be to set up a page on your server with the following javascript:

    (function() {
      var app = {
        launchApp: function() {
          window.location.replace("myapp://");
          this.timer = setTimeout(this.openWebApp, 1000);
        },
    
        openWebApp: function() {
          window.location.replace("http://itunesstorelink/");
        }
      };
    
      app.launchApp();
    })();
    

    This basically attempts to redirect to your app and sets a timeout to redirect to the app store if it fails.

    You could even make the code a little more smart, and check the user agent to see if they are an ios user, an android user, or a webuser, and then redirect them appropriately.

提交回复
热议问题