获取appid与版本号

plus.runtime.getProperty(plus.runtime.appid, (info) => {
	//版本号
	this.version = info.version;
	//appid
    this.appID = info.appid;
})

注意:只能在真机运行或者打包后的app,在hbuilderx不能运行,会报错

根据地址去下载新版本app
下载地址调取后端接口来获取

// 下载新版本
doUpData() {
    uni.showLoading({
        title: '更新中……'
    })
    uni.downloadFile({//执行下载
        url: this.url, //下载地址
        success: downloadResult => {//下载成功
            uni.hideLoading();
            if (downloadResult.statusCode == 200) {
                uni.showModal({
                    title: '',
                    content: '更新成功,确定现在重启吗?',
                    confirmText: '重启',
                    confirmColor: '#EE8F57',
                    success: function(res) {
                        if (res.confirm == true) {
                            plus.runtime.install(//安装
                                downloadResult.tempFilePath, {
                                    force: true
                                },
                                function(res) {
                                    utils.showToast('更新成功,重启中');
                                    plus.runtime.restart();
                                }
                            );
                        }
                    }
                });
            }
        }
    });
}
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐