Skip to content

mpx.startBluetoothDevicesDiscovery(Object object)

开始搜寻附近的蓝牙外围设备。此操作比较耗费系统资源,请在搜索并连接到设备后调用 mpx.stopBluetoothDevicesDiscovery 停止搜索。

参考文档

参数

Object object

属性类型默认值必填说明
servicesstring[][]要搜索的蓝牙设备主服务 UUID 列表。
allowDuplicatesKeybooleanfalse是否允许重复上报同一设备。
intervalnumber0上报设备的间隔,单位为 ms。
powerLevelstringmedium扫描模式,可选值为 lowmediumhigh;档位越高,扫描越快、耗电越多。
successfunction接口调用成功的回调函数。
failfunction接口调用失败的回调函数。
completefunction接口调用结束的回调函数,成功、失败都会执行。

RN 平台说明

RN Android 和 Harmony 环境会将 powerLevel 转换为底层 react-native-ble-manager 的扫描模式:

powerLevelscanModeHarmony 扫描模式
low0SCAN_MODE_LOW_POWER
medium1SCAN_MODE_BALANCED
high2SCAN_MODE_LOW_LATENCY

RN iOS 不支持调整扫描模式,该参数会由底层系统忽略。Harmony 环境需要具备 SystemCapability.Communication.Bluetooth.Core 系统能力。

示例代码

js
mpx.startBluetoothDevicesDiscovery({
  services: [],
  allowDuplicatesKey: true,
  powerLevel: "high",
  success (res) {
    console.log(res)
  }
})