Mobile Safari calls the local app or goes to the App store to download

Source: Internet
Author: User

Requirements:

How to allow users to access a URL via a mobile Safari, to open an app on iOS directly, and if the app isn't installed, jump directly to the app download page in the Apps store.

Preparatory work
    1. OpenURL function and URL Scheme for iOS SDK
    2. JavaScript's window.location and settimeout functions
Code implementation

Below to open the warm Island app as an example, the JS implementation section is as follows

window.location = ‘nuandao://web2app‘;setTimeout(function() {    window.location = ‘itms-apps://itunes.apple.com/cn/app/nuan-dao/id583307376?mt=8‘}, 30);

See the effect:
1. If you have already installed the Warm Island app, you will open the APP2 directly. If you haven't installed it, you'll jump directly to the download page of the App Store

Ideas:
1. Window.location Connection execution Open application 2. Delay opening App Store download app page

Specifically, when you open the link, Mobile Safari directly opens the local app by pointing to URL Scheme via window.location. Otherwise open the download page after 30ms. If the application successfully opened, the life cycle is activated, then the browser's status into the background, all the actions on the page are written off, obviously timeout will be clear off, if you do not open the application is returned 404, then the page will automatically jump after 30ms. Note that the Items-apps is not http://, otherwise there may be an error.

Then combine the mobile judgment to realize the demand.

if(/(iphone|ipad|ipod)/i.test(navigator.userAgent)) {    $(‘#header‘).addClass(‘ios‘);                   // 调整结构    $(‘#J_itunes-cover‘).show();                    // 显示下载条    $(‘#J_itunes‘).click(function() {        window.location = ‘nuandao://web2app‘;        setTimeout(function() {            window.location = ‘itms-apps://itunes.apple.com/cn/app/nuan-dao/id583307376?mt=8‘        }, 30);    });}

This article reproduced: http://jsdashi.com/development/511.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.