9***@qq.com
9***@qq.com
  • 发布:2021-02-25 09:57
  • 更新:2021-02-25 09:57
  • 阅读:1790

热更新plus.runtime.restart()重启后程序已经更新成功,再次启动又提示一遍热更新重启

分类:HBuilderX

热更新plus.runtime.restart()重启后程序已经更新成功,再次启动又提示一遍热更新重启。 难道是有缓存? 代码如下,有偿咨询!!!!

onLaunch: function() {
this.$actionengine.setPageStorageCacheToGlobal();
var that = this;
this.$actionengine.getPageSettingJson(that,"./App","Link_RegCloud").then(
 (res) => {
// #ifdef APP-PLUS
this.UpdJsonInfo = {};
this.Appversion = plus.runtime.version;
//console.log("当前应用版本:"+(this.Appversion).split('.').join(''));
this.UpdJsonInfo["_App_Code"] = plus.runtime.appid;
this.UpdJsonInfo["User_Role"] = uni.getStorageSync("Platform_User_Role");
this.UpdJsonInfo["User_Area"] = uni.getStorageSync("Platform_Region");
this.UpdJsonInfo["_App_Version"] = (this.Appversion).split('.').join('');
this.UpdJsonInfo["_App_OS"] = uni.getSystemInfoSync().platform;
this.UpdJsonInfo["_App_ExeStore"] = "True";
var that = this;
this.$actionengine.eventFuncHandling(that, "./App", "AppUpdate").then(
(res) => {
let sUpdUrl = this.UpdJsonInfoRet["Update_Url"];
//console.log(1,sUpdUrl)
//判断是否存在整包更新的URL,如果存在那么直接打开更新否则判断热更新
if ((sUpdUrl != "") && (typeof(sUpdUrl) != 'undefined')) {
plus.runtime.openURL(sUpdUrl)
} else{
this.UpdJsonInfo = {};
plus.runtime.getProperty(plus.runtime.appid,function(inf){
uni.setStorageSync("_version",inf.version);
})
this.Appversion = uni.getStorageSync("_version");
//console.log("当前应用版本:"+(this.Appversion).split('.').join(''));
this.UpdJsonInfo["_App_Code"] = plus.runtime.appid;
this.UpdJsonInfo["User_Role"] = uni.getStorageSync("Platform_User_Role");
this.UpdJsonInfo["User_Area"] = uni.getStorageSync("Platform_Region");
this.UpdJsonInfo["_App_Version"] = (this.Appversion).split('.').join('');
this.UpdJsonInfo["_App_OS"] = uni.getSystemInfoSync().platform;
this.UpdJsonInfo["_App_ExeStore"] = "False";
var that = this;
this.$actionengine.eventFuncHandling(that, "./App", "AppUpdate").then(
(res) => {
//清缓存
let Is_Must = this.UpdJsonInfoRet["Is_Must"];
let downloadLink = '';
let sUpdUrl = this.UpdJsonInfoRet["Update_Url"];
let ready = false;
//console.log(2,sUpdUrl)
if ((sUpdUrl != "") && (typeof(sUpdUrl) != 'undefined')) {
plus.screen.lockOrientation('portrait-primary'); //竖屏正方向锁定
const updated = uni.getStorageSync('updated'); // 尝试读取storage
if (updated.completed === true) {
// 如果上次刚更新过
// 删除安装包及安装记录
console.log('安装记录被删除,更新成功');
uni.removeSavedFile({
filePath: updated.packgePath,
success: res => {
uni.removeStorageSync('updated');
}
});
} else if (updated.completed === false) {
uni.removeStorageSync('updated');
plus.runtime.install(updated.packgePath, {
force: true
});
uni.setStorage({
key: 'updated',
data: {
completed: true,
packgePath: updated.packgePath
},
success: res => {
console.log('成功安装上次的更新,应用需要重启才能继续完成');
}
});
uni.hideLoading();
uni.showModal({
title: '提示',
content: '应用将重启以完成更新',
showCancel: false,
complete: () => {
plus.runtime.restart();
}
});
} else{
if (sUpdUrl.match(RegExp(/.wgt/))) {
downloadLink = sUpdUrl;
ready = true;
if (ready) {
console.log('任务开始');
let downloadTask = uni.downloadFile({
url: downloadLink,
success: res => {
if (res.statusCode === 200) {
// 保存下载的安装包
console.log('保存安装包');
uni.saveFile({
tempFilePath: res.tempFilePath,
success: res => {
const packgePath = res.savedFilePath;
// 保存更新记录到stroage,下次启动app时安装更新
uni.setStorage({
key: 'updated',
data: {
completed: false,
packgePath: packgePath
},
success: () => {
console.log('成功保存记录');
}
});
// 任务完成,关闭下载任务
console.log('任务完成,关闭下载任务,下一次启动应用时将安装更新');
downloadTask.abort();
downloadTask = null;
}
});
}
}
});
} else {
console.log('下载地址未准备,无法开启下载任务');
}
} else {
if (Is_Must == 'True') {
uni.showModal({
showCancel: false,
confirmText: '立即更新',
title: '发现新版本',
content: res.des,
success: res => {
if (res.confirm) {
if (uni.getSystemInfoSync().platform == 'android') {
uni.downloadFile({
url: sUpdUrl,
success: downloadResult => {
if (downloadResult.statusCode === 200) {
plus.runtime.install(
downloadResult.tempFilePath, {
force: false
},
d => {
console.log('install success...');
plus.runtime.restart();
},
e => {
console.error('install fail...');
}
);
}
}
});
}
if (uni.getSystemInfoSync().platform == 'ios') {
plus.runtime.openURL(sUpdUrl, function(res) {});
}
} else if (res.cancel) {
console.log('取消');
}
}
});
} else {
uni.showModal({
title: '发现新版本',
confirmText: '立即更新',
cancelText: '下次更新',
content: res.des,
success: res => {
if (res.confirm) {
if (uni.getSystemInfoSync().platform == 'android') {
uni.downloadFile({
url: sUpdUrl,
success: downloadResult => {
if (downloadResult.statusCode === 200) {
plus.runtime.install(
downloadResult.tempFilePath, {
force: false
},
d => {
console.log('install success...');
plus.runtime.restart();
},
e => {
console.error('install fail...');
}
);
}
}
});
}
if (uni.getSystemInfoSync().platform == 'ios') {
plus.runtime.openURL(sUpdUrl, function(res) {});
}
} else if (res.cancel) {
console.log('取消');
}
}
});
}
}
}
}
})

                        }  
                });   
                // #endif   
        }).catch(err => {  
                uni.navigateTo({  
                    url: '../public/login'  
                })                    
        });   

        uni.getSystemInfo({  
                success:function(e){  
                    Vue.prototype.statusBar = e.statusBarHeight  
                    // #ifndef MP  
                    if(e.platform == 'android') {  
                        Vue.prototype.customBar = e.statusBarHeight + 50  
                    }else {  
                        Vue.prototype.customBar = e.statusBarHeight + 45  
                    }  
                    // #endif  

                    // #ifdef MP-WEIXIN  
                    let custom = wx.getMenuButtonBoundingClientRect()  
                    Vue.prototype.customBar = custom.bottom + custom.top - e.statusBarHeight  
                    // #endif  

                    // #ifdef MP-ALIPAY  
                    Vue.prototype.customBar = e.statusBarHeight + e.titleBarHeight  
                    // #endif  
                }  
        });   
        console.log('App Launch')  
        // #ifdef APP-PLUS  
        const _self = this;  
        const _handlePush = function(message) {  
            /**  
             * 通过 vuex 来同步页面的数据,仅做演示。  
             * 实际开发中,这里可能是跳转到某个页面等操作,请根据自身业务需求编写。  
             */  
            _self.updatePushMessage(message);  
        };  
        plus.push.addEventListener('click', function(message) {  
            plus.nativeUI.toast('push click');  
            _handlePush(message);  
        });  
        plus.push.addEventListener('receive', function(message) {  
            plus.nativeUI.toast('push receive');  
            _handlePush(message);  
        });  
        // #endif  
    },  
2021-02-25 09:57 负责人:无 分享
已邀请:

该问题目前已经被锁定, 无法添加新回复