Bluetooth beacons
Once the premium module has been added to your app, you may use the following APIs to access its functionality .

Overview

This module allows the scanning of nearby Bluetooth Low-Energy beacons that conform to the iBeacon spec. It provides a native bridge to retrieve the list of nearby beacons and their identifying information.
An iBeacon continuously broadcasts three identifiers: a UUID, major, and minor. UUID is a long random identifier that should be customized for each implementation. Major and minor are integers between 0 and 65535 that can be used to differentiate each individual beacon. For example, a retailer may have one UUID across all of their iBeacon deployments used for their retail customers, and another UUID used for employees. Each store may have a major identifier, and each individual beacon would have a different minor identifier.
The beacon broadcast data also encodes the emitting signal power. By comparing this to the actual received signal power, devices can estimate their distance from each beacon.
As Bluetooth beacons can be used to identify the user's physical location, this is considered a privacy sensitive function. iOS requires the user to grant location permissions. Android also requires the user to grant permissions starting with Android 10.

Implementation Guide

You must provide a specific UUID to scan for iBeacons. Apple does not permit iOS devices to scan for all UUIDs.
Create a function that will receive the beacon data. Then open the url gonative://beacon/scan?callback=callback&uuid=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
For example:
1
// define this function, but do not call it yourself!
2
function callback(data) {
3
if (data.success) {
4
alert('I found ' + data.beacons.length + ' beacons');
5
}
6
}
7
8
window.location.href = "gonative://beacon/scan?callback=callback&uuid=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
9
Copied!
Within a few seconds of a successful scan, the app will run your callback function with a data object with the fields:
    success: set to true. This does not indicate that any beacons were found, only that the scan did not encounter errors.
    beacons: an array of beacon objects, each containing the fields:
      format: a string, set to "iBeacon"
      uuid: a string
      major: an integer
      minor: an integer
      rssi: signal strength in decibels
      proximity (iOS only): "immediate", "near", "far", or "unknown"
      accuracy (iOS only): the accuracy of the proximity calculation in meters
      distance: (Android only): the estimated distance of the beacon in meters
For example:
1
{
2
"success": true,
3
"beacons": [
4
{
5
"format": "iBeacon",
6
"uuid": "9C615AD4-8E6A-53BC-BC27-82171491A2WA",
7
"major": 1000,
8
"minor": 123,
9
"rssi": -52,
10
"proximity": "immediate",
11
"accuracy": 0.1413
12
},
13
{
14
"format": "iBeacon",
15
"uuid": "9C615AD4-8E6A-53BC-BC27-82171491A2WB",
16
"major": 1001,
17
"minor": 1321,
18
"rssi": -78,
19
"proximity": "near",
20
"accuracy": 4.5321
21
}
22
]
23
}
24
Copied!
If the scan fails, the data object will have the fields:
    success: set to false
    error: a string that describes why the scan failed
For example:
1
{
2
"success": false,
3
"error": "This device does not support Bluetooth LE"
4
}
5
Copied!
Typical reasons for a scan to fail include the device not having the necessary hardware, Bluetooth being disabled, or the user denying location permissions.
Last modified 1yr ago