- 小程序为什么无法获取到手机的蓝牙地址
[图片] 不明白为什么无法获取到手机的蓝牙地址 [代码]/*开启蓝牙设备*/[代码][代码]openBluetoothAdapter: [代码][代码]function[代码] [代码]() {[代码][代码] [代码][代码]var[代码] [代码]that = [代码][代码]this[代码][代码];[代码][代码] [代码][代码]wx.openBluetoothAdapter({[代码][代码] [代码][代码]success: [代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]console.log(res)[代码][代码] [代码][代码]wx.onBluetoothAdapterStateChange([代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]console.log([代码][代码]"蓝牙适配器状态变化"[代码][代码], res)[代码][代码] [代码][代码]that.setData({[代码][代码] [代码][代码]isbluetoothready: res.available,[代码][代码] [代码][代码]searchingstatus: res.discovering[代码][代码] [代码][代码]})[代码][代码] [代码][代码]})[代码][代码] [代码][代码]that.startBluetoothDevicesDiscovery()[代码] [代码] [代码][代码]}[代码][代码] [代码][代码]})[代码][代码]},[代码][代码]/*获取本机蓝牙适配器状态*/[代码][代码]getBluetoothAdapterState: [代码][代码]function[代码] [代码]() {[代码][代码] [代码][代码]var[代码] [代码]that = [代码][代码]this[代码][代码];[代码][代码] [代码][代码]wx.getBluetoothAdapterState({[代码][代码] [代码][代码]success: [代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]console.log(res)[代码][代码] [代码][代码]if[代码] [代码](!res.discovering) {[代码][代码] [代码][代码]that.startBluetoothDevicesDiscovery()[代码][代码] [代码][代码]}[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码][代码]},[代码][代码]startBluetoothDevicesDiscovery: [代码][代码]function[代码] [代码]() {[代码][代码] [代码][代码]var[代码] [代码]that = [代码][代码]this[代码][代码];[代码][代码] [代码][代码]wx.startBluetoothDevicesDiscovery({[代码][代码] [代码][代码]allowDuplicatesKey: [代码][代码]true[代码][代码],[代码][代码] [代码][代码]success: [代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]console.log(res)[代码][代码] [代码][代码]},[代码][代码] [代码][代码]fail: [代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]console.log(res)[代码][代码] [代码][代码]},[代码][代码] [代码][代码]})[代码] [代码] [代码][代码]that.onBluetoothDeviceFound();[代码] [代码]},[代码][代码]/**获取在小程序蓝牙模块生效期间所有已发现的蓝牙设备,包括已经和本机处于连接状态的设备。*/[代码][代码]getBluetoothDevices: [代码][代码]function[代码] [代码]() {[代码][代码] [代码][代码]var[代码] [代码]that = [代码][代码]this[代码][代码];[代码][代码] [代码][代码]wx.getBluetoothDevices({[代码][代码] [代码][代码]success: [代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]console.log(res)[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码] [代码]},[代码][代码]/**监听寻找到新设备的事件*/[代码][代码]onBluetoothDeviceFound: [代码][代码]function[代码] [代码]() {[代码][代码] [代码][代码]var[代码] [代码]that = [代码][代码]this[代码][代码];[代码][代码] [代码][代码]that.getConnectedBluetoothDevices()[代码][代码] [代码][代码]console.log([代码][代码]"search............"[代码][代码])[代码] [代码] [代码][代码]wx.onBluetoothDeviceFound([代码][代码]function[代码] [代码](devices) {[代码][代码] [代码][代码]console.log([代码][代码]'new device list has founded'[代码][代码])[代码][代码] [代码][代码]console.dir(devices)[代码][代码] [代码][代码]that.getBluetoothDevices()[代码][代码] [代码][代码]})[代码] [代码]},[代码][代码]/**根据 uuid 获取处于已连接状态的设备*/[代码][代码]getConnectedBluetoothDevices: [代码][代码]function[代码] [代码]() {[代码][代码] [代码][代码]var[代码] [代码]that = [代码][代码]this[代码][代码];[代码][代码] [代码][代码]that.createBLEConnection()[代码][代码] [代码][代码]wx.getConnectedBluetoothDevices({[代码][代码] [代码][代码]success: [代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]console.log(res)[代码][代码] [代码][代码]//[代码] [代码] [代码][代码]}[代码][代码] [代码][代码]})[代码][代码]},[代码]
2018-03-31 - 为什么小程序的蓝牙开启后一直报10008,discovering 为false
[图片] [图片] [代码]/*开启蓝牙设备*/[代码][代码] [代码][代码]openBluetoothAdapter: [代码][代码]function[代码] [代码]() {[代码] [代码] [代码][代码]var[代码] [代码]that = [代码][代码]this[代码][代码];[代码][代码] [代码][代码]wx.showLoading({[代码][代码] [代码][代码]title: [代码][代码]'开启蓝牙适配'[代码][代码] [代码][代码]});[代码][代码] [代码][代码]wx.openBluetoothAdapter({[代码][代码] [代码][代码]success: [代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]console.log([代码][代码]"初始化蓝牙适配器"[代码][代码]);[代码][代码] [代码][代码]console.log(res);[代码][代码] [代码][代码]that.getBluetoothAdapterState();[代码][代码] [代码][代码]},[代码][代码] [代码][代码]fail: [代码][代码]function[代码] [代码](err) {[代码][代码] [代码][代码]console.log(err);[代码][代码] [代码][代码]wx.showToast({[代码][代码] [代码][代码]title: [代码][代码]'蓝牙初始化失败'[代码][代码],[代码][代码] [代码][代码]icon: [代码][代码]'success'[代码][代码],[代码][代码] [代码][代码]duration: 2000[代码][代码] [代码][代码]})[代码][代码] [代码][代码]setTimeout([代码][代码]function[代码] [代码]() {[代码][代码] [代码][代码]wx.hideToast()[代码][代码] [代码][代码]}, 2000)[代码][代码] [代码][代码]}[代码][代码] [代码][代码]});[代码][代码] [代码][代码]wx.onBluetoothAdapterStateChange([代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]var[代码] [代码]available = res.available;[代码][代码] [代码][代码]if[代码] [代码](available) {[代码][代码] [代码][代码]that.getBluetoothAdapterState();[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码][代码] [代码][代码]},[代码][代码] [代码][代码]/*获取本机蓝牙适配器状态*/[代码][代码] [代码][代码]getBluetoothAdapterState: [代码][代码]function[代码] [代码]() {[代码][代码] [代码][代码]var[代码] [代码]that = [代码][代码]this[代码][代码];[代码][代码] [代码][代码]wx.getBluetoothAdapterState({[代码][代码] [代码][代码]success: [代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]var[代码] [代码]available = res.available,[代码][代码] [代码][代码]discovering = res.discovering;[代码][代码] [代码][代码]console.log(res)[代码][代码] [代码][代码]if[代码] [代码](!available) {[代码][代码] [代码][代码]wx.showToast({[代码][代码] [代码][代码]title: [代码][代码]'设备无法开启蓝牙连接'[代码][代码],[代码][代码] [代码][代码]icon: [代码][代码]'success'[代码][代码],[代码][代码] [代码][代码]duration: 2000[代码][代码] [代码][代码]})[代码][代码] [代码][代码]setTimeout([代码][代码]function[代码] [代码]() {[代码][代码] [代码][代码]wx.hideToast()[代码][代码] [代码][代码]}, 2000)[代码][代码] [代码][代码]}[代码][代码] [代码][代码]else[代码] [代码]{[代码][代码] [代码][代码]if[代码] [代码](!discovering) {[代码][代码] [代码][代码]that.startBluetoothDevicesDiscovery();[代码][代码] [代码][代码]that.getConnectedBluetoothDevices();[代码][代码] [代码][代码]}[代码][代码] [代码][代码]}[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码][代码] [代码][代码]},[代码][代码] [代码][代码]startBluetoothDevicesDiscovery: [代码][代码]function[代码] [代码]() {[代码][代码] [代码][代码]var[代码] [代码]that = [代码][代码]this[代码][代码];[代码][代码] [代码][代码]wx.showLoading({[代码][代码] [代码][代码]title: [代码][代码]'蓝牙搜索'[代码][代码] [代码][代码]});[代码][代码] [代码][代码]wx.startBluetoothDevicesDiscovery({[代码][代码] [代码][代码]services: [],[代码][代码] [代码][代码]allowDuplicatesKey: [代码][代码]false[代码][代码],[代码][代码] [代码][代码]success: [代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]if[代码] [代码](!res.isDiscovering) {[代码][代码] [代码][代码]that.getBluetoothAdapterState();[代码][代码] [代码][代码]}[代码][代码] [代码][代码]else[代码] [代码]{[代码][代码] [代码][代码]that.onBluetoothDeviceFound();[代码][代码] [代码][代码]}[代码][代码] [代码][代码]},[代码][代码] [代码][代码]fail: [代码][代码]function[代码] [代码](err) {[代码][代码] [代码][代码]console.log(err);[代码][代码] [代码][代码]}[代码][代码] [代码][代码]});[代码] [代码] [代码][代码]},[代码][代码] [代码][代码]/**获取在小程序蓝牙模块生效期间所有已发现的蓝牙设备,包括已经和本机处于连接状态的设备。*/[代码][代码] [代码][代码]getBluetoothDevices: [代码][代码]function[代码] [代码]() {[代码][代码] [代码][代码]var[代码] [代码]that = [代码][代码]this[代码][代码];[代码][代码] [代码][代码]wx.getBluetoothDevices({[代码][代码] [代码][代码]success: [代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]console.log(res)[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码] [代码] [代码][代码]},[代码][代码] [代码][代码]/**监听寻找到新设备的事件*/[代码][代码] [代码][代码]onBluetoothDeviceFound: [代码][代码]function[代码] [代码]() {[代码][代码] [代码][代码]var[代码] [代码]that = [代码][代码]this[代码][代码];[代码][代码] [代码][代码]wx.onBluetoothDeviceFound([代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]console.log([代码][代码]'new device list has founded'[代码][代码])[代码][代码] [代码][代码]console.log(res);[代码][代码] [代码][代码]if[代码] [代码](res.devices[0]) {[代码][代码] [代码][代码]var[代码] [代码]name = res.devices[0][[代码][代码]'name'[代码][代码]];[代码][代码] [代码] [代码] [代码][代码]var[代码] [代码]deviceId = res.devices[0][[代码][代码]'deviceId'[代码][代码]];[代码][代码] [代码][代码]that.deviceId = deviceId;[代码][代码] [代码][代码]console.log(that.deviceId);[代码][代码] [代码][代码]that.startConnectDevices();[代码][代码] [代码] [代码] [代码][代码]}[代码][代码] [代码][代码]})[代码] [代码] [代码][代码]},[代码][代码] [代码][代码]/**根据 uuid 获取处于已连接状态的设备*/[代码][代码] [代码][代码]getConnectedBluetoothDevices: [代码][代码]function[代码] [代码]() {[代码][代码] [代码][代码]var[代码] [代码]that = [代码][代码]this[代码][代码];[代码][代码] [代码][代码]that.createBLEConnection()[代码][代码] [代码][代码]wx.getConnectedBluetoothDevices({[代码][代码] [代码][代码]success: [代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]console.log(res)[代码][代码] [代码][代码]//[代码] [代码] [代码][代码]}[代码][代码] [代码][代码]})[代码][代码] [代码][代码]},[代码]
2018-03-31 - (小米手机苹果手机)关于小程序蓝牙无法搜索到任何设备
[图片] [图片] 这里显示一直为空 [图片]
2018-03-30