在UC瀏覽器打開鏈接喚醒app,如果沒有安裝該app,則跳轉到appstore下載該應用
需要在工程中設置如下:
1、打開工程中的myapp-Info.plist文件
2、打開文件中新增URL TYPES的一項,具體如下圖所示:
在你要打開的網頁中使用如下的代碼:
<!-- a標籤的鏈接,設置爲對應的下載鏈接;點擊打開的動作,在click事件中註冊 -->
<a href="https://itunes.apple.com/cn/app/id892359007" id="openApp">我的應用</a>
<script type="text/javascript">
document.getElementById('openApp').onclick = function(e){
// 通過iframe的方式試圖打開APP,如果能正常打開,會直接切換到APP,並自動阻止a標籤的默認行爲
// 否則打開a標籤的href鏈接
var ifr = document.createElement('iframe');
ifr.src = 'laoshi://';
ifr.style.display = 'none';
document.body.appendChild(ifr);
window.setTimeout(function(){
document.body.removeChild(ifr);
},3000)
};
</script>
用UC瀏覽器打開後出現我的應用的鏈接
最後在appdelegate中的中實現如下方法:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return YES;
}
這樣就可以在iPhone端的UC瀏覽器點擊我的應用鏈接地址啓動自己的app了
延伸閱讀:http://www.wahenzan.com/a/mdev/ios/2014/1217/365.html
http://www.w3ctech.com/topic/287