微信小程序判断微信客户端版本是否支持蓝牙

微信客户端是否支持蓝牙判断

onLaunch: function() {
    ... ...
    this.globalData.sysinfo = wx.getSystemInfoSync();
    }
getModel() { //获取手机型号
    return this.globalData.sysinfo["model"];
  },

  getVersion() {//获取微信版本号
    console.log("check_version:" + this.globalData.sysinfo["version"]);
    return this.globalData.sysinfo["version"];
  },

  getSystem() {//获取操作系统版本
    return this.globalData.sysinfo["system"];
  },

  getPlatform() {//获取客户端平台
    console.log("check_version:" + this.globalData.sysinfo["platform"]);
    return this.globalData.sysinfo["platform"];
  },

  getSDKVersion() {//获取客户端基础库
    return this.globalData.sysinfo["SDKVersion"];
  },

  //版本比较
  versionWXComparison(standardVersion, appVersion) {
    standardVersion = standardVersion.split('.');
    appVersion = appVersion.split('.');

    const len = Math.max(standardVersion.length, appVersion.length);
    while (standardVersion.len < len) {
      standardVersion.push('0');
    }
    while(appVersion.length < len) {
      appVersion.push('0');
    }

    for(let i = 0; i < len; i++) {
      const standardVersion_num = parseInt(standardVersion[i]);
      const appVersion_num = parseInt(appVersion[i]);

      if (standardVersion_num < appVersion_num) {
        return 1;
      } else if (standardVersion_num > appVersion_num) {
        return -1;
      }
    }

    return 0;
  },

  checkWXVersion() {
    if (this.getPlatform() == 'android' && this.versionWXComparison('6.5.7', this.getVersion()) < 0) {
      wx.showModal({
        title: '提示',
        content: '当前微信版本过低,请更新至最新版本',
        showCancel: false
      });
    } else if (this.getPlatform() == 'ios' && this.versionWXComparison('6.5.6', this.getVersion()) < 0) {
      wx.showModal({
        title: '提示',
        content: '当前微信版本过低,请更新至最新版本',
        showCancel: false
      })
    }
  }
发布了161 篇原创文章 · 获赞 154 · 访问量 10万+

猜你喜欢

转载自blog.csdn.net/zhangying1994/article/details/88667684