Taro.openBluetoothAdapter(option)
Initializes the Bluetooth module.
Notes
- Other Bluetooth-related APIs can only be used after
Taro.openBluetoothAdapter
is called. Otherwise, the API will return an error (errCode=10000). - When the user's Bluetooth switch is off or the phone does not support Bluetooth, calls to
Taro.openBluetoothAdapter
will return an error (errCode=10001). This indicates the phone's Bluetooth feature is unavailable. In such cases, after initializing the Mini Program Bluetooth module, you can useTaro.onBluetoothAdapterStateChange
to listen on changes to the phone's Bluetooth status. You can also call all Bluetooth module APIs.
Type
(option?: Option) => Promise<CallbackResult>
Parameters
Option
Property | Type | Required | Description |
---|---|---|---|
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 |
state
Property | Description |
---|---|
0 | Unknown |
1 | Reseting |
2 | Not support |
3 | Unauthorised |
4 | Not open |
Sample Code
Taro.openBluetoothAdapter({
success: function (res) {
console.log(res)
}
})
API Support
API | WeChat Mini-Program | H5 | React Native |
---|---|---|---|
Taro.openBluetoothAdapter | ✔️ |