IOS开发笔记之推广安装(用网页判断是否安装App)

来源:互联网 发布:淘宝居家家怎么那么火 编辑:程序博客网 时间:2024/06/05 09:49

IOS开发笔记之推广安装(用网页判断是否安装App)

在做App推广的时候,我们经常会用到网页链接下载,亦或是一张二维码,最常见的做法就是将App在iTunes中的下载链接嵌入,当用户扫描或者点击网页下载时,判断用户是否安装了该App,如果有安装,则直接打开,如果没有安装,则跳转iTunes直接到该App的下载页面。
点击链接或者扫描二维码下载的前提是你需要知道对应App的打开协议。比如微信的weixin://,这个协议都是我们自己在Infoplist中添加的。

infoplist

然后添加如下代码

<!-- a标签的链接,设置为对应的下载链接;点击打开的动作,在click事件中注册 --><a href="https://itunes.apple.com/cn/app/要打开的app在iTunes中的id" id="openApp">要打开的app名字</a><script type="text/javascript">    document.getElementById('openApp').onclick = function(e){        // 通过iframe的方式试图打开APP,如果能正常打开,会直接切换到APP,并自动阻止a标签的默认行为        // 否则打开a标签的href链接        var ifr = document.createElement('iframe');        ifr.src = 'app的协议';        ifr.style.display = 'none';        document.body.appendChild(ifr);        window.setTimeout(function(){            document.body.removeChild(ifr);        },3000)    };</script>

如果是二维码的话,用如下代码

<!-- a标签的链接,设置为对应的下载链接;点击打开的动作,在click事件中注册 --><a href="https://itunes.apple.com/cn/app/要打开的app在iTunes中的id" id="openApp" style="display: none">要打开的app名字</a><script type="text/javascript">    document.getElementById('openApp').onclick = function(e){        // 通过iframe的方式试图打开APP,如果能正常打开,会直接切换到APP,并自动阻止a标签的默认行为        // 否则打开a标签的href链接        var ifr = document.createElement('iframe');        ifr.src = 'app协议';        ifr.style.display = 'none';        document.body.appendChild(ifr);        window.setTimeout(function(){            document.body.removeChild(ifr);        },3000)    };    document.getElementById('openApp').click();</script>    
0 0
原创粉丝点击