# wx.openBluetoothAdapter(Object object)

Start from base library version 1.1.0. Please remaining backward compatible.

with Promise style call: Supported

Mini Program plugin: Support, need to Mini Program base library version no less than 1.9.6

Initialize the Bluetooth module. iOS Up-on host/Is called each time in slave (peripheral) mode, and the corresponding mode

# parameter

# Object object

attribute type Default values Required Introductions Minimum version
mode string central no Bluetooth mode, available as master/From equipment, only iOS Need. 2.10.0
success function no Interface calls the successful callback function
fail function no Interface calls failed callback functions
complete function no Interface calls the end of the callback function (call success or failure will be executed)

object.mode Legal value

value Introductions Minimum version
central Host mode
peripheral Slave (peripheral) mode

# error

Error code Error message Introductions
0 ok normal
-1 already connect Connected
10000 not init Uninitialized Bluetooth adapter
10001 not available The current Bluetooth adapter is not available
10002 No device Specified device not found
10003 connection fail Connection failure
10004 No service Specified service not found
10005 No characteristic Did not find the specified signature.
10006 No connection Current connection disconnected
10007 property not support Current feature does not support this operation
10008 system error All other system reported anomalies
10009 system not support Android System specific, system version below 4.3 Not supported WAS
10012 operate time out Connection Timeout
10013 invalid_data Connect deviceId Is empty or incorrectly formatted

# object.fail Callback function returns state Parameters only iOS)

Status code Introductions
0 Unknown
1 Reset
2 Not supported
3 Not authorized
4 Not open

# Be careful

  • Other Bluetooth related API Must be wx.openBluetoothAdapter Used after the call. otherwise API Returns an error (errCode = 10000).
  • When the user's Bluetooth switch is not turned on or the phone does not support Bluetooth, call the wx.openBluetoothAdapter An error is returned (errCode = 10001) indicating that the phone's Bluetooth feature is not available. At this time the Mini Program bluetooth module has been initialized, you can use wx.onBluetoothAdapterStateChange Monitor the phone's Bluetooth status change, you can also call all the API of Bluetooth module.

# sample code

Preview with Developer Tool

  success (res) {