5+API plus.runtime.install没反应总结

页面源代码

<template>
	<view class="version">
		<u-popup v-model="show" mode="center" :mask-close-able="false">
			<view class="upVersion">
				<image class="top" src="../../static/icon/2.png" mode="">image>
				<view class="text">
					<view class="til">版本升级view>
					<view class="cont">
						<text>更新内容text>
						<text v-html="android.app_content">text>
					view>
					<view class="btn">
						<u-button class="btn1" v-if="!upshow" @click="up">立即升级u-button>
						<u-line-progress v-else height="80" active-color="#26A69A" :percent="progress" :striped="true"
							:striped-active="true">u-line-progress>

					view>
				view>
				<image class="bom" src="../../static/icon/3.png" mode="" @click="close">image>
			view>
		u-popup>
	view>
template>
<script>
	export default {
		data() {
			return {
				show: false,
				upshow: false, //是否显示进度条
				android: {}, //是否更新数据,请求接口后存起来备用。
				progress: 0, //下载进度
			}
		},
		onShow() {
			this.$http.get("Index/getVersion").then(res => {
				if (res.code == 200) {
					this.android = res.data;
					let version = this.android.app_version.split(".").join(""); // 需要更新的版本 1.0.1  === 101
					plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {
						let time_version = widgetInfo.versionCode; // 当前APP的版本 : 100
						console.log('time_version' + time_version);
						if (time_version < version) { // 当前版本小于更新版本,提示更新,
							this.show = true; //可以弹出更新提示框
							uni.hideTabBar(); // APP 无法遮挡tabbar,直接隐藏掉
						}
					})
				}
			})
		},

		methods: {
			//升级
			up() {
				this.progress = 0;
				this.upshow = true; //切换进度条显示
				//开启下载任务
				var dtask = plus.downloader.createDownload(this.android.down_url, {
					method: "GET"
				}, (d, status)=> {
					if (status == 200) {
						console.log("下载成功安装: " + d.filename);
						plus.runtime.install(d.filename)
						setTimeout(() => {
							this.close();
						}, 1500)
					} else {
						plus.nativeUI.alert("安装失败,请稍候重试: " + status)
						setTimeout(() => {
							this.close();
						}, 1500)
					}
				});
				
				// 下载任务状态变化事件,计算进度条数值
				dtask.addEventListener('statechanged', (task)=> {
					if(task.state == 3){
						let progress = dtask.downloadedSize / dtask.totalSize * 100;
						this.progress = Math.trunc(progress)
					}
				});
				dtask.start();
			},
			close() {
				this.show = false; //关闭更新弹窗
				this.upshow = false; //关闭进度条
				uni.showTabBar(); //显示tabbar
			}
		},
	}
script>
<style scoped lang="scss">
	.version {
		/deep/.u-drawer {
			.u-mode-center-box {
				background: transparent;
			}

			.upVersion {
				width: 640rpx;
				border-radius: 8rpx;

				.top {
					width: 640rpx;
					height: 280rpx;
					display: block;
				}

				.text {
					padding: 0 40rpx 160rpx 40rpx;
					min-height: 470rpx;
					background: #fff;
					position: relative;

					.til {
						font-size: 34rpx;
						font-weight: bold;
						text-align: center;
					}

					.cont {
						uni-text {
							line-height: 56rpx;
							display: block;
							font-size: 28rpx;
							color: #505660;
						}
					}

					.btn {
						position: absolute;
						bottom: 40rpx;
						left: 10%;
						width: 80%;
						text-align: center;
						margin: auto;

						.btn1 {
							width: 100%;
							height: 80rpx;
							line-height: 80rpx;
							background: #26A69A;
							border-radius: 48rpx;
							font-weight: 34rpx;
							color: #fff;
							font-weight: bold;
						}
					}
				}

				.bom {
					display: block;
					width: 64rpx;
					height: 64rpx;
					margin: 100rpx auto 0;
				}

			}
		}

	}
style>

效果图如下

5+API plus.runtime.install没反应总结_第1张图片

plus.runtime.install() 没反应的问题总结

1、首先检查权限问题

"",
"",

HBuilder2.6.3+开始Goog Play渠道默认不再添加此权限,因为GooglePlay审核规则禁止应用下载apk更新,必须通过上传GooglePlay审核更新
安装apk需要的权限,应用中使用plus.runtime.install升级应用则需要此权限

2、尝试修改配置manifest.json将targetSdkVersion改为26或更高 最高建议28。

"minSdkVersion" : "14",
"targetSdkVersion" : "26"

参考规范:manifest.json
5+API plus.runtime.install没反应总结_第2张图片

在这里插入图片描述
5+API plus.runtime.install没反应总结_第3张图片

以上两步还不行,先检查是不是代码的问题

我在对接5+项目时,下载APP因为一直使用的uniapp的 uni.downloadFile 下载。
虽然也下载成功了,也返回了链接。但就是plus.runtime.install(res.tempFilePath)安装不上。
后来换成了5+API的plus.downloader.createDownload()下载,解决问题。

你可能感兴趣的:(5+API,BUG,前端,javascript,开发语言)