微信小程序蓝牙搜索不到的问题

安卓

1. 开启手机蓝牙(未开启会提示信息,点击去开启按钮直接跳转手机设置,开启蓝牙)

  打开手机,设置——蓝牙

2. 开启手机位置信息(未开启会提示信息)

  打开手机,设置——位置信息

3. 开启微信位置信息权限(未开启会提示信息,点击去开启按钮直接跳转手机微信授权管理页,开启微信位置信息权限)

  打开手机,设置——应用——微信——权限——位置信息

4. 开启微信附近设备权限(暂时无法提示信息,小程序端无法判断)

  打开手机,设置——应用——微信——权限——附近设备

5. 开启小程序蓝牙权限(未开启会直接跳转小程序设置页面)

IOS

1. 开启手机蓝牙(未开启会提示信息)

  打开手机,设置——蓝牙

2. 开启微信蓝牙权限(未开启会提示信息,点击去开启按钮直接跳转手机微信授权管理页,开启微信位置信息权限)

  打开手机,设置——微信——蓝牙

3. 开启小程序蓝牙权限(未开启会直接跳转小程序设置页面)

开启小程序位置信息权限(目前看不需要开启)

这些暂时自己遇到问题汇总,因为这个设置没有开启导致搜索不到蓝牙的问题。小程序使用者又不知道需要开启哪些设置,在程序中做了一些判断提示信息,提醒小程序使用者开启这些设置。

后面会继续补充一些代码等相关文章。

CheckSystemInfo(){
  let that=this;
  return new Promise((resolve, reject) => {
    //获取设备设置
    let systemSetting = wx.getSystemSetting();
    let bluetoothEnabled = systemSetting.bluetoothEnabled;
    let locationEnabled = systemSetting.locationEnabled;
    //获取设备基础信息
    let deviceInfo = wx.getDeviceInfo();
    let platform = deviceInfo.platform;  
    /*
      ios	iOS微信(包含 iPhone、iPad)
      android	Android微信
      windows	Windows微信
      mac	macOS微信
      devtools	微信开发者工具
    */
    //获取微信APP授权设置
    let appAuthorizeSetting = wx.getAppAuthorizeSetting();
    let bluetoothAuthorized = appAuthorizeSetting.bluetoothAuthorized; //允许微信使用蓝牙的开关(仅 iOS 有效)
    let locationAuthorized = appAuthorizeSetting.locationAuthorized;
    if(!bluetoothEnabled)
    {
      let showCancel = false;
      let confirmText = '确定';
      if (platform=='android') {
        showCancel = true;
        confirmText = '去开启';
      }
      wx.showModal({
        content: '请进入手机设置开启蓝牙',
        showCancel:showCancel,
        confirmText:confirmText,
        success: function (res) {
          if (res.confirm) {
            console.log('用户点击确定')
            if (platform=='android') {
              wx.openSystemBluetoothSetting({
                success (res) {
                  console.log(res)
                }
              })
            }
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      });
      resolve(false);
    }
    else
    {
      //小程序的蓝牙权限
      wx.getSetting({
        success: (res) => {
          //console.log(res, res.authSetting[scopeName],!res.authSetting[scopeName], scopeName)
          //小程序 ** 权限
          if (!res.authSetting['scope.bluetooth']) {
            // 没有权限
            wx.showModal({
              title: '提示',
              content: '请开启小程序蓝牙权限',
              showCancel: false,
              success: modalSuccess => {
                wx.openSetting();
              }
            });
            resolve(false);
          }
          else
          {
            if (platform=='android') {
              if (!locationEnabled) {
                wx.showModal({
                  content: '请进入手机设置开启位置信息',
                  showCancel:false,
                  success: function (res) {
                    console.log(res);
                  }
                });
                resolve(false);
              }
              else
              {
                if (locationAuthorized!=='authorized') {
                  wx.showModal({
                    content: '请进入手机设置开启微信应用的位置信息权限',
                    showCancel:true,
                    confirmText:'去开启',
                    success: function (res) {
                      console.log(res);
                      if (res.confirm) {
                        console.log('用户点击确定')
                        wx.openAppAuthorizeSetting({
                          success (res) {
                            console.log('系统微信授权管理页', res)
                          }
                        })
                      } else if (res.cancel) {
                        console.log('用户点击取消')
                      }
                    }
                  });
                  resolve(false);
                }
                else
                {
                  resolve(true);
                }
              }
            }
            else if (platform=='ios')
            {
              if (bluetoothAuthorized!=='authorized') {
                wx.showModal({
                  content: '请进入手机设置开启微信应用的蓝牙权限',
                  showCancel:true,
                  confirmText:'去开启',
                  success: function (res) {
                    console.log(res);
                    if (res.confirm) {
                      console.log('用户点击确定')
                      wx.openAppAuthorizeSetting({
                        success (res) {
                          console.log('系统微信授权管理页', res)
                        }
                      })
                    } else if (res.cancel) {
                      console.log('用户点击取消')
                    }
                  }
                });
                resolve(false);
              }
              else
              {
                resolve(true);
              }
            }
            else
            {
              resolve(true);
            }
          }
        }, 
        fail: (err) => {
          reject(err)
        }
      })
    }
  });
}

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

wsk198726

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

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

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

打赏作者

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

抵扣说明:

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

余额充值