问题描述:当用户微信版本过低,可能会导致某一些功能无法正常使用,与基础库版本不兼容。
//获取用户版本信息
getUserSystem() {
let res = uni.getSystemInfoSync(); //获取系统信息(里面包含微信版本号)
console.log('手机信息:', res);
let system = res.system.split(' ');
console.log('手机系统:', system);
let version;
if (system[0] == "iOS") { //如果是ios系统
version = this.compareVersion(res.version, '7.0.12');
} else {
version = this.compareVersion(res.version, '7.0.13');
}
if (version < 0) {
uni.showModal({
title: '提示',
content: '当前微信版本过低,部分功能可能无法使用,请及时更新',
})
}
},
//判断版本号
compareVersion(v1, v2) {
v1 = v1.split('.')
v2 = v2.split('.')
const len = Math.max(v1.length, v2.length)
while (v1.length < len) {
v1.push('0')
}
while (v2.length < len) {
v2.push('0')
}
for (let i = 0; i < len; i++) {
const num1 = parseInt(v1[i])
const num2 = parseInt(v2[i])
if (num1 > num2) {
return 1 //大于限定版本
} else if (num1 < num2) {
return -1 //小于限定版本
}
}
return 0 //等于限定版本
},
详情版本信息请至:https://developers.weixin.qq.com/miniprogram/dev/framework/client-lib/version.html
版权声明:本文为weixin_48495574原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。