uniapp 安卓 ios更新方法

2 篇文章 0 订阅

安卓更新方式

androidUpdateMethod() {
// this.downloadUrl 下载地址,后端返回
				var dtask = plus.downloader.createDownload(this.downloadUrl, {}, function(d, status) {
					// 下载完成  
					if (status == 200) {
						plus.runtime.install(plus.io.convertLocalFileSystemURL(d.filename), {}, {}, function(
							error) {
							uni.showToast({
								title: '安装失败',
								duration: 2000
							});
						})
					} else {
						uni.showToast({
							title: '更新失败',
							duration: 2000
						});
					}
				});

				dtask.addEventListener("statechanged", (task) => {
					// console.log(task.state)
					switch (task.state) {
						case 1: {
							console.log('开始下载');
							this.download = true  // 开始下载
							this.updateMask = true  // 开启遮罩层
							break;
						}
						case 2: {
							console.log('链接到服务器...');
							this.download = true
							this.updateMask = true
							break;
						}
						case 3: {
							let progressVal = 0; //写成局部变量试试
							progressVal = (task.downloadedSize / task.totalSize) * 100;
							this.percent = parseInt(progressVal)  // 下载进度条
							break;
						}
						case 4: {
							cnosole.log('监听下载完成');
							this.download = false
							this.updateMask = false
						}
					}
				}, false);
				dtask.start();
			},

ios更新方式

		iosIpdatemethod() {
				uni.showModal({
					content: '当前有新版本更新,是否前往更新?',
					success: res => {
						if (res.confirm) {
							plus.runtime.openURL(this.downloadUrl);
						}
					}
				})
			},

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值