Skip to main content
Version: Next

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.

Reference

Type

(option: Option) => Promise<Promised>

Parameters

Promised

PropertyTypeDescription
errMsgstringsuccess: ok; fail: error message.

Option

PropertyTypeRequiredDescription
allowDuplicatesKeybooleanNoIndicates 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.。
intervalnumberNoThe device reporting interval. 0 indicates new devices are immediately reported. Other values indicate devices are reported based on the specified interval.
servicesstring[]NoThe 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) => voidNoThe callback function used when the API call completed (always executed whether the call succeeds or fails)
fail(res: any) => voidNoThe callback function for a failed API call
success(res: Result) => voidNoThe 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

APIWeChat Mini-ProgramH5React Native
Taro.startBluetoothDevicesDiscovery✔️