# startBluetoothDiscovery ^6.8
开始扫描附近蓝牙设备
# 请求参数
| Prop | Type | Default | Comment | 
|---|---|---|---|
| mac | String | N/A | //安卓:蓝牙Mac地址;iOS:外设uuid | 
| name | String | N/A | 筛选的名字 | 
| duration | String | N/A | 扫描持续时间 单位秒 | 
# 接口调用示例
  let params =  {
        name: 'QWQ001-', // 可选 筛选的名字
        mac: '1812',  // 可选 筛选的mac
        duration: '5', //单位秒, 可选
      };
  this.$bridge
    .startBluetoothDiscovery(params)
    .then(res => {    
      this.$alert(res)
    })
    .catch(err => {
      this.$toast(err)
    })
 1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
# 返回参数
- 成功时返回
 
| Prop | Type | Comment | 
|---|---|---|
code |  Number |  - | 
name |  String |  名字 | 
rssi |  String |  - | 
deviceId |  String |  - | 
# 返回示例
- 当扫描到的蓝牙设备(蓝牙信息)时,APP通知插件结果
 - 扫描期间会多次通知,每发现一个记录通知一次
 
// 通过receiveMessageFromApp事件返回。
this.$bridge.addEventListener('receiveMessageFromApp', (res) => {
  console.log('startBluetoothDiscovery', JSON.stringify(res))
  this.$bridge.showToast({
    title: JSON.stringify(res),
    duration: 5,
  })
})
 1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9