uniapp实现ios端app跳转appstore更新应用

废话不多说直接上代码,以下只是跳转到APP store 的方法

//在App Store Connect中的App Store下的app信息,可找到appleId
let appleId= 1515706501
plus.runtime.launchApplication({
    action: `itms-apps://itunes.apple.com/cn/app/id${appleId}?mt=8`
}, function(e) {
    console.log('Open system default browser failed: ' + e.message);
});

以下是安卓和ios如何实现更新应用完成代码

//type:click时主动点击实现更新。否则在页面初始化显示有更新(显示版本号)
checkAppUpdata(type){
    let appVersion = ''
    uni.getSystemInfo({
        success: function(e) {
            appVersion = e.platform
        }
    })
    let _this = this
    //#ifdef APP-PLUS
    plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => {
        //此处为访问后台是否有更新
        this.http.appInfo().then( res => {
            //如果后台版本比当前版本高则更新
            if (res.version> parseInt(wgtinfo.versionCode)) {
                if(type === 'click'){
                    uni.showModal({
                        title: "版本更新",
                        content: res.t.desc, //更新描述
                        confirmText:'立即更新',
                        cancelText:'稍后进行',
                        success: sucRes => {
                            if (sucRes.confirm) {
                                //如果是安卓直接更新下载
                                if(appVersion === 'android'){
                                    uni.downloadFile({
                                        url: res.result.download_url,
                                        success: data => {
                                            if (data.statusCode === 200) { 
                                                plus.runtime.install(data.tempFilePath, {  
                                                    force: false  
                                                }, function() {
                                                    plus.runtime.restart();  
                                                });  
                                             }  
                                        }
                                    })
                                //如果是ios跳转到app store
                                }else{
                                    //在App Store Connect中的App Store下的app信息,可找到appleId
                                    let appleId= 1515706501
                                    plus.runtime.launchApplication({
                                        action: `itms-apps://itunes.apple.com/cn/app/id${appleId}?mt=8`
                                    }, function(e) {
                                        console.log('Open system default browser failed: ' + e.message);
                                    });
                                }
                            }
                        }
                    })
                //页面初始化如果有更新则显示
                }else{
                    this.version = '发现新版本'
                }
            }else{
                if(type === 'click'){
                    uni.showToast({icon:'none',title:'当前已是最新版本'})
                }else{
                    this.version= `版本 ${wgtinfo.version}`
                }
            }
        })
    })
    //#endif
},

猜你喜欢

转载自www.cnblogs.com/ghc520/p/13391673.html