Taro.startBluetoothDevicesDiscovery(option)
Starts searching for nearby Bluetooth peripherals. This operation consumes a large amount of system resources. After searching for and connecting to a device, be sure to call the Taro.stopBluetoothDevicesDiscovery
method to stop searching.
Type
(option: Option) => Promise<Promised>
Parameters
Promised
Property | Type | Description |
---|---|---|
errMsg | string | success: ok; fail: error message. |
Option
Property | Type | Required | Description |
---|---|---|---|
allowDuplicatesKey | boolean | No | Indicates whether a device can be reported multiple times. If yes, the Taro.onBlueToothDeviceFound method will report a device multiple times, but with different RSSI values.。 |
interval | number | No | The device reporting interval. 0 indicates new devices are immediately reported. Other values indicate devices are reported based on the specified interval. |
services | string[] | No | The list of primary service UUIDs of Bluetooth devices to be discovered. Some Bluetooth devices will broadcast their own primary service uuids. If this parameter is set, only Bluetooth devices with primary services corresponding to the uuids in the broadcast package are discovered. We recommend using this parameter to filter out nearby Bluetooth devices that are not needed. |
complete | (res: any) => void | No | The callback function used when the API call completed (always executed whether the call succeeds or fails) |
fail | (res: any) => void | No | The callback function for a failed API call |
success | (res: Result) => void | No | The callback function for a successful API call |
Sample Code
// For example, the primary service UUID of the smart Bluetooth light of the WeChat hardware platform is FEE7. When this parameter is provided, only the device with the primary service UUID of FEE7 is searched for.
Taro.startBluetoothDevicesDiscovery({
services: ['FEE7'],
success: function (res) {
console.log(res)
}
})
API Support
API | WeChat Mini-Program | H5 | React Native |
---|---|---|---|
Taro.startBluetoothDevicesDiscovery | ✔️ |