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任何回调都不进行
你好,麻烦在手机微信那里上传下日志: 我->设置->帮助与反馈右上角有个上报日志的入口,麻烦提供一下微信号,时间点
mode: 'central',
mode:'central'改成 peripheral 试试