用App打开
最近项目中涉及到了这个功能,拿到需求时候让我这个小白一脸懵逼,好在看了看博客后还是实现了。
涉及到的逻辑:
- 判断当前环境 ;
- 根据不同的环境进行跳转到 “下载” 或者直接 “打开应用” ;
- 当前是 微信中 打开的话,需要进行额外的操作(下面会有详细写);
代码
- 主要代码
openApp: function (param) {
var localUrl = this.createScheme(param)
var openIframe = this.createIfream()
if (this.isMobile()) {
if (!this.isWeChat()) {
if (this.isIos()) {
window.location.href = localUrl
var loadDateTime = Date.now()
setTimeout(() => {
var timeOutDateTime = Date.now()
if (timeOutDateTime - loadDateTime < 1000) {
// ios下载地址
window.location.href = this.DOWNLOAD_URL
}
}, 25)
} else if (this.isAndroid()