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
- OpenURL function and URL Scheme for iOS SDK
- 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