Skip to content

Bluetooth-Beacon

stopBeaconDiscovery

TIP

The API usage is as follows: wx.stopBeaconDiscovery(Object object)

  • Functional description: Stop searching for nearby Beacon devices.
  • Parameters and descriptions: Object object。
    PropertiesTypeDefault valueRequiredDescription
    successFunction-NoCallback function for successful interface call
    failFunction-NoCallback function for failed interface call
    completeFunction-NoCallback function for interface call completion (executed regardless of success or failure)
  • Error code
    Error codeError messageDescription
    0okNormal
    11000unsupportSystem or device not supported
    11001bluetooth service unavailableBluetooth service unavailable
    11002location service unavailableLocation service unavailable
    11003already startSearch has started
    10004not startBeaconDiscoverySearch has not started
    11005system errorSystem error
    11006invalid dataParameter incorrect

startBeaconDiscovery

TIP

The API usage is as follows: wx.startBeaconDiscovery(Object object)

  • Functional description: Search for nearby Beacon devices started.

  • Parameters and descriptions: Object object。

    PropertiesTypeDefault valueRequiredDescription
    uuidsArray.<string>-YesList of UUIDs broadcast by Beacon devices
    ignoreBluetoothAvailablebooleanfalseNoWhether to check the Bluetooth switch is only valid in iOS. Starting from iOS 11, you can still use Beacon service even if you turn off Bluetooth in the control panel
    successFunction-NoCallback function for successful interface call
    failFunction-NoCallback function for failed interface call
    completeFunction-NoCallback function for interface call completion (executed regardless of success or failure)
  • Error code

    Error codeError messageDescription
    0okNormal
    11000unsupportSystem or device not supported
    11001bluetooth service unavailableBluetooth service unavailable
    11002location service unavailableLocation service unavailable
    11003already startSearch has started
    10004not startBeaconDiscoverySearch has not started
    11005system errorSystem error
    11006invalid dataParameter incorrect
  • Sample code:

js
wx.startBeaconDiscovery({
  success(res) { }
})

onBeaconUpdate

TIP

The API usage is as follows: wx.onBeaconUpdate(function listener)

  • Functional description: Listen for Beacon device update events, only one listener can be registered

  • Parameters and descriptions: function listener,Listening function of Beacon device update event, parameter Object res is as follows:

    PropertiesTypeDescription
    beaconsArray.<BeaconInfo>List of all Beacon devices currently searched
  • Sample code:

js
wx.onBeaconUpdate(res => {
   console.log(res.beacons)
})

offBeaconUpdate

TIP

The API usage is as follows: wx.offBeaconUpdate()

  • Functional description: Remove all listening functions of Beacon device update event.

  • Sample code:

js
wx.offBeaconUpdate()

onBeaconServiceChange

TIP

The API usage is as follows: wx.onBeaconServiceChange(function listener)

  • Functional description: Listening for Beacon service status change event, only one listening function can be registered.

  • Parameters and descriptions: function listener,Listening function of Beacon service status change event, parameter Object res is as follows:

    PropertiesTypeDescription
    availablebooleanIs the service currently available
    discoveringbooleanIs it currently in search state
  • Sample code:

js
wx.onBeaconServiceChange(res => {
   console.log(res.available, res.discovering)
})

offBeaconServiceChange

TIP

The API usage is as follows: wx.offBeaconServiceChange()

  • Functional description: Remove all listening functions of Beacon service status change event.

  • Sample code:

js
wx.offBeaconServiceChange()

getBeacons

TIP

The API usage is as follows: wx.getBeacons(Object object)

  • Functional description: Get all Beacon devices that have been searched.

  • Parameters and descriptions: Object object。

    PropertiesTypeDefault valueRequiredDescription
    successFunction-NoCallback function for successful interface call
    failFunction-NoCallback function for failed interface call
    completeFunction-NoCallback function for interface call completion (executed regardless of success or failure)
  • object.success callback function parameters: Object res。

    PropertiesTypeDescription
    beaconsArray.<BeaconInfo>List of Beacon devices
  • Error code

    Error codeError messageDescription
    0okNormal
    11000unsupportSystem or device not supported
    11001bluetooth service unavailableBluetooth service unavailable
    11002location service unavailableLocation service unavailable
    11003already startSearch has started
    10004not startBeaconDiscoverySearch has not started
    11005system errorSystem error
    11006invalid dataParameter incorrect

BeaconInfo

  • Functional description: Beacon device

  • Attributes and descriptions

    PropertiesTypeDescription
    uuidstringUUID broadcast by Beacon device
    majornumberPrimary ID of Beacon device
    minornumberSecondary ID of Beacon device
    proximitynumberEnumeration value indicating device distance (iOS only)
    accuracynumberDistance of Beacon device, unit m. On iOS, when proximity is 0, accuracy is -3
    rssinumberIndicates the signal strength of the device, in dBm
    • Legal values
      ValueDescription
      0The signal is too weak to calculate the distance, or it is not an iOS device
      1Very close
      2Relatively close
      3Far