当微信版本过低,基础库较低,导致部分功能无法正常使用时,需要微信升级
App({
globalData: {}, onLaunch: function () { this.compareVersion(); } compareVersion() { //校验小程序版本 let systemInfo = this.globalData.getSystemInfo || wx.getSystemInfoSync(); let paltsfrom = systemInfo.platform || systemInfo.osName, version = systemInfo.version || systemInfo.hostVersion, SDKVersion = systemInfo.SDKVersion || systemInfo.hostSDKVersion; if (this.getVersion(SDKVersion, '2.32.3') >= 0 || (paltsfrom == 'ios' && this.getVersion(paltsfrom, '8.0.36') >= 0) || (paltsfrom == 'android' && this.getVersion(paltsfrom, '8.0.35') >= 0)) {} else { // 如果希望用户在最新版本的客户端上体验您的小程序,可以这样子提示 wx.showModal({ title: '提示', content: '当前微信版本(' + version + ')过低,部分功能将会无法正常使用,请升级到最新微信版本后重试。', cancelText: '取消升级', confirmText: '确定升级', success: function (res) { if (res.confirm) { // 更新微信客户端版本 wx.updateWeChatApp(); } } }) } }, getVersion(v1, v2) { //校验两个版本号,返回:1-表示v1比v2新,0-表示v1和v2是同一个版本,-1-表示v1比v2老 v1 = v1.split('.') v2 = v2.split('.') var len = Math.max(v1.length, v2.length) while (v1.length < len) { v1.push('0') } while (v2.length < len) { v2.push('0') } for (var i = 0; i < len; i++) { var num1 = parseInt(v1[i]) var num2 = parseInt(v2[i]) if (num1 > num2) { return 1 } else if (num1 < num2) { return -1 } } return 0 }, })
标签:paltsfrom,提示,微信,v1,v2,版本,systemInfo From: https://www.cnblogs.com/czhowe/p/17843630.html