收藏
回答

ios调用wx.createBLEPeripheralServer无回调?

wx.getSetting({
          success(res) {
            console.log(res.authSetting)
            //判断是否有'scope.bluetooth'属性
            if (res.authSetting.hasOwnProperty('scope.bluetooth')) {
              //'scope.bluetooth'属性存在,且为false
              if (!res.authSetting['scope.bluetooth']) {
                //弹窗授权
                wx.openSetting({
                  success(res) {
                    console.log(res.authSetting)
                  }
                })
              } else {
                wx.openBluetoothAdapter({
                  mode'central',
                  success(res) => {
                    console.log('蓝牙连接成功');
                    wx.createBLEPeripheralServer({
                      success(res) => {
                        console.log("创建BLE外设【成功】")
                        this.server = res.server
                        this.setData({
                          server: res.server
                        })
                        console.log(this.server);
                      },
                      fail(res) => {
                        console.log("创建BLE外设【失败】", res)
                      },
                      complete(res) => {
                        console.info("创建BLE外设【完成】", res)
                        console.log("开始广播")
                
                        this.startAdvertising();
                      }
                    })
                  }
                })
              }
            }
            else {
              //'scope.bluetooth'属性不存在,需要授权
              wx.authorize({
                scope'scope.bluetooth',
                success() {
                  // 用户已经同意小程序使用手机蓝牙功能,后续调用 蓝牙 接口不会弹窗询问
                  console.log(res.authSetting)
                }
              })
            }
          }
        })

已经可以进行到openBluetoothAdapter的success回调,能打印到'蓝牙连接成功',但是wx.createBLEPeripheralServer任何回调都不进行

回答关注问题邀请回答
收藏

2 个回答

  • 社区技术运营专员--阳光
    社区技术运营专员--阳光
    2023-08-07

    你好,麻烦在手机微信那里上传下日志: 我->设置->帮助与反馈右上角有个上报日志的入口,麻烦提供一下微信号,时间点

    2023-08-07
    有用
    回复
  • tan
    tan
    2023-08-15
    mode'central',
    

    mode:'central'改成 peripheral 试试

    2023-08-15
    有用
    回复 1
    • tan
      tan
      2023-08-15
      peripheral  从机(外围设备)模式
      2023-08-15
      回复
登录 后发表内容