uniapp打包app后,安卓端、IOS端版本升级

onReady() {
	// #ifdef APP-PLUS
	// app获取版本
	var _this = this;
	_this.getVersion();
	// #endif
},
methods: {
            /**
			 *  app端版本更新 start
			 */
			getVersion() {
				let _this = this;
				let platform = uni.getSystemInfoSync().platform;
				console.log(platform);
			
				// 获取应用版本信息
				plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => {
					console.log("==获取应用版本信息==");
					console.log(JSON.stringify(wgtinfo));
					console.log(wgtinfo.versionCode);
					var versionCode = wgtinfo.versionCode;
			
					uni.$u.http.get('/api/other.Webconfig/get_webconfigdata', {
						params: {}
					}).then(res => {
						console.log("==检查版本更新==");
						console.log(res);
						// 下载地址
						var androidUrl = res.data.web_config_str.app_android_url;
						var iosUrl = res.data.web_config_str.app_ios_url;
			
						// 新版本
						var androidVersion_new = res.data.web_config_str.app_android_version_code;
						var iosVersion_new = res.data.web_config_str.app_ios_version_code;
			
						// 安卓版本对比,是否更新
						if (parseInt(androidVersion_new) > parseInt(versionCode) && platform ==
							'android') {
							uni.showModal({
								title: "发现新版本",
								content: "确认下载更新?",
								success: (res) => {
									if (res.confirm) {
										// console.log('用户点击确定');
										_this.downloadAndroid(androidUrl);
									} else if (res.cancel) {
										console.log('用户点击取消');
									}
								}
							})
						}
			
						// ios版本对比,是否更新
						if (parseInt(iosVersion_new) > parseInt(versionCode) && platform == 'ios') {
							uni.showModal({
								title: "发现新版本",
								content: "确认下载更新?",
								success: (res) => {
									if (res.confirm) {
										// console.log('用户点击确定');
										plus.runtime.launchApplication({
											action: iosUrl
										}, function(e) {
											console.log(
												'Open system default browser failed: ' +
												e.message);
										});
									} else if (res.cancel) {
										console.log('用户点击取消');
									}
								}
							})
						}
					}).catch(res => {
						console.log(res);
					})
				})
			
			},
			
			// 下载安卓端app
			downloadAndroid(androidUrl) {
				uni.showLoading({
					title: '更新中...'
				})
				// 执行下载
				uni.downloadFile({
					url: androidUrl,
					success: (downloadRes) => {
						uni.hideLoading();
						if (downloadRes.statusCode == 200) {
							uni.showModal({
								title: '更新成功',
								content: '是否现在重启吗?',
								confirmText: '重启',
								confirmColor: '#EE8F57',
								success: function(res) {
									if (res.confirm == true) {
										//安装
										plus.runtime.install(
											downloadRes.tempFilePath, {
												force: true
											},
											function(res) {
												utils.showToast('更新成功,重启中');
												plus.runtime.restart();
											}
										);
									}
								}
							});
						}
					}
				});
			},
			
			/**
			 *  app端版本更新 end
			 */
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

 康 

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值