BeaconsModule Class
Item Index
Methods
Properties
Constants
- BACKGROUND_DATA_AUTHORIZATION_STATUS_AUTHORIZED
- BACKGROUND_DATA_AUTHORIZATION_STATUS_DENIED
- BACKGROUND_DATA_AUTHORIZATION_STATUS_NOT_DETERMINED
- BACKGROUND_DATA_AUTHORIZATION_STATUS_RESTRICTED
- BEACON_PROXIMITY_FAR
- BEACON_PROXIMITY_IMMEDIATE
- BEACON_PROXIMITY_NEAR
- BEACON_PROXIMITY_UNKNOWN
- LOCATION_MANAGER_AUTHORIZATION_STATUS_AUTHORIZED
- LOCATION_MANAGER_AUTHORIZATION_STATUS_DENIED
- LOCATION_MANAGER_AUTHORIZATION_STATUS_NOT_DETERMINED
- LOCATION_MANAGER_AUTHORIZATION_STATUS_RESTRICTED
- PERIPHERAL_MANAGER_STATE_POWERED_OFF
- PERIPHERAL_MANAGER_STATE_POWERED_ON
- PERIPHERAL_MANAGER_STATE_RESETTING
- PERIPHERAL_MANAGER_STATE_UNAUTHORIZED
- PERIPHERAL_MANAGER_STATE_UNINITIALIZED
- PERIPHERAL_MANAGER_STATE_UNKNOWN
- PERIPHERAL_MANAGER_STATE_UNSUPPORTED
- REGION_STATE_INSIDE
- REGION_STATE_OUTSIDE
- REGION_STATE_UNKOWN
Methods
createBeaconRegion
-
params
Creates a BeaconRegion object that can be used to start advertising an iBeacon.
Parameters:
-
params
ObjectAn object with the following properties (see the properties of the BeaconRegion class for details):
-
identifier
StringA unique identifier to associate with the returned region object. You use this identifier to differentiate regions within your application.
-
UUID
StringThe UUID of the beacon.
-
[major]
Number optionalThe major number of the beacon. If not specified, the major and minor numbers of the beacon are ignored.
-
[minor]
Number optionalThe minor number of the beacon. If not specified, the minor number of the beacon is ignored.
-
[notifyEntryStateOnDisplay=false]
Boolean optionalWhen set to
true
, the beacon notifications will be sent only when the user turns on the display and the device is already inside the region.
-
Returns:
initPeripheralManager
-
[params]
Initializes the module's internal peripheral manager object. This function must be called in an app that acts as a peripheral before any other function can be used.
Parameters:
-
[params]
Object optionalAn object with the following properties:
-
[showPowerAlert=true]
Boolean optionalBoolean indicating that the system should, if Bluetooth is powered off when the peripheral is instantialized, display a warning dialog to the user. This parameter was introduced in version 1.1.0 of the module.
-
[restoreIdentifier]
String optionalA string containing a unique identifier for the peripheral manager that is being instantiated. This identifier is used by the system to identify a specific peripheral manager instance for restoration and, therefore, must remain the same for subsequent application executions in order for the manager to be restored. See also the peripheralWillRestoreState event. This parameter was introduced in version 1.1.0 of the module.
-
Returns:
requestAlwaysAuthorization
()
Void
When the current authorization status is LOCATION_MANAGER_AUTHORIZATION_STATUS_NOT_DETERMINED, this method runs asynchronously and prompts the user to grant permission to the app to use location services. The user prompt contains the text from the NSLocationAlwaysUsageDescription key in your app’s Info.plist file. The presence of that key is required when calling this method.
After the status is determined, the app will receive an BeaconsModule/locationManagerAuthorizationChanged:event event.
If the current authorization status is anything other than LOCATION_MANAGER_AUTHORIZATION_STATUS_NOT_DETERMINED, this function does nothing.
Important: You must call this function or the requestWhenInUseAuthorization function prior to using beacon services.
Requesting “Always” authorization is discouraged by Apple because of the potential negative impacts to user privacy. You should request this level of authorization only when doing so offers a genuine benefit to the user.
Returns:
requestRegionState
-
params
Retrieves the state of a region asynchronously.
Parameters:
-
params
ObjectAn object with the following properties:
-
beaconRegion
BeaconRegionThe region of interest.
-
Returns:
requestWhenInUseAuthorization
()
Void
When the current authorization status is LOCATION_MANAGER_AUTHORIZATION_STATUS_NOT_DETERMINED, this method runs asynchronously and prompts the user to grant permission to the app to use location services. The user prompt contains the text from the NSLocationWhenInUseUsageDescription key in your app’s Info.plist file. The presence of that key is required when calling this method.
After the status is determined, the app will receive an BeaconsModule/locationManagerAuthorizationChanged:event event.
If the current authorization status is anything other than LOCATION_MANAGER_AUTHORIZATION_STATUS_NOT_DETERMINED, this function does nothing.
Important: You must call this function or the requestAlwaysAuthorization function prior to using beacon services.
If the user grants “when-in-use” authorization to your app, your app can range beacons but not monitor beacon regions.
Returns:
retrieveMonitoredRegions
()
Void
Retrieves the currently monitored beacon regions. Note that this function will initialize the location manager if it's not already initialized. Thus this function, unlike the monitoredRegions property, is guaranteed to return the correct result in every case. In particular, this function is a key component of the restoration process that needs to take place when the app is restarted into the background in response to a beacon related event.
Important: Call this function after you attached the appropriate event handlers for the enteredRegion, exitedRegion, and regionStateUpdated events. If the app was restarted due to a beacon related event, that event will be fired immediately after this function is called.
Async function; returns the results in a retrievedMonitoredRegions event.
Returns:
startAdvertising
-
[params]
Instructs the module's internal peripheral manager to start advertising.
Important: You must call the initPeripheralManager function first!
Note: In the Beacons
module, this function can only be used
to advertise beacon regions.
Supported advertising data types are ADVERT_DATA_KEY_LOCAL_NAME and ADVERT_DATA_KEY_SERVICE_UUIDS. When in the foreground, an application can utilize up to 28 bytes of space in the initial advertisement data for any combination of the supported advertising data types. If this space is used up, there are an additional 10 bytes of space in the scan response that can be used only for the local name. Note that these sizes do not include the 2 bytes of header information that are required for each new data type. Any service UUIDs that do not fit in the allotted space will be added to a special "overflow" area, and can only be discovered by an iOS device that is explicitly scanning for them. While an application is in the background, the local name will not be used and all service UUIDs will be placed in the "overflow" area.
Parameters:
-
[params]
Object optionalObject containing the data to be advertised.
-
ADVERT_DATA_KEY_LOCAL_NAME
StringLocal name. Note that ADVERT_DATA_KEY_LOCAL_NAME is the constant whose value (!) is to be used as the key, like so:
params[BluetoothLE.ADVERT_DATA_KEY_LOCAL_NAME] = ...
-
ADVERT_DATA_KEY_SERVICE_UUIDS
Array of StringsService UUIDs. Note that ADVERT_DATA_KEY_SERVICE_UUIDS is the constant whose value (!) is to be used as the key, like so:
params[BluetoothLE.ADVERT_DATA_KEY_SERVICE_UUIDS] = ...
-
beaconRegion
BeaconRegionAn object created using the createBeaconRegion method. If this parameter is present, other parameters except
measuredPower
are ignored. -
[measuredPower]
Number optionalThe received signal strength indicator (RSSI) value (measured in decibels) for the device. This value represents the measured strength of the beacon from one meter away and is used during ranging. If not specified, the default value for the device will be used.
-
Returns:
startRangingBeacons
-
params
Starts the delivery of notifications for beacons in the specified region.
Parameters:
-
params
ObjectAn object with the following properties:
-
beaconRegion
BeaconRegionThe region of interest.
-
Returns:
startRegionMonitoring
-
params
Starts monitoring the specified region.
You must call this method once for each region you want to monitor. If an existing region with the same identifier is already being monitored by the application, the old region is replaced by the new one. Note that "identifier" literally means the identifier property, not the UUID! The regions you add using this method are stored in the monitoredRegions property.
Parameters:
-
params
ObjectAn object with the following properties:
-
beaconRegion
BeaconRegionThe region of interest.
-
Returns:
stopAdvertising
()
Void
Instructs the module's internal peripheral manager to stop advertising.
Returns:
stopRangingBeacons
-
[params]
Stops the delivery of notifications for beacons in the specified region. If no beacon region is specified, then it stops ranging for all regions.
Parameters:
-
[params]
Object optionalAn object with the following properties:
-
beaconRegion
BeaconRegionThe region of interest.
-
Returns:
stopRegionMonitoring
-
[params]
Stops the delivery of notifications for beacons in the specified region. If no beacon region is specified, then it stops ranging for all regions.
Parameters:
-
[params]
Object optionalAn object with the following properties:
-
beaconRegion
BeaconRegionThe region of interest.
-
Returns:
Properties
backgroundDataAuthorizationStatus
Number
read-only
The current authorization status for sharing data while backgrounded. You can use it to detect restricted access and hide UI instead of prompting for access. Possible values are the BACKGROUND_DATA_AUTHORIZATION_STATUS_* constants.
filterDuplicateBeacons
Boolean
Determines whether the beacons included with the
rangedBeacons
event will be filtered for duplicates. Defaults to false
.
A beacon is considered a duplicate of another if their UUID, major, and
minor numbers are all the same.
isAdvertising
Boolean
read-only
Whether or not the the module's internal peripheral manager is currently advertising data.
locationManagerAuthorizationStatus
Number
read-only
Authorization status of the Location Manager for this app. Its value is one of the LOCATION_MANAGER_AUTHORIZATION_STATUS_* constants.
monitoredRegions
Array of BeaconRegions
read-only
The beacon regions monitored by all location manager objects. Note that this property will be undefined when the app is restarted into the background. Use the retrieveMonitoredRegions function to retrieve the list of monitored regions in that case.
peripheralManagerState
Number
read-only
State of the module's internal peripheral manager. Its value is one of the PERIPHERAL_MANAGER_STATE_* constants.
rangedRegions
Array of BeaconRegions
read-only
The regions currently being tracked using ranging.
restoredPeripheralManagerIdentifiers
Array of Strings
read-only
Each string in the array represents the restoration identifier for a
peripheral manager object. This is the same string you assigned to the
restoreIdentifier
parameter of the
{{#crossLink "BeaconsModule/initPeripheralManager:method}}{{/crossLink}}
function.
wasLocationLaunch
Boolean
read-only
True
if the application was launched due to a location event.
In the context of this module, a "location event" is an event related to
beacons. Note however that other type of location events might also trigger
the app to be launched.
Constants
BACKGROUND_DATA_AUTHORIZATION_STATUS_AUTHORIZED
Number
One of the possible values of the backgroundDataAuthorizationStatus property. User has authorized this application to share data while backgrounded.
BACKGROUND_DATA_AUTHORIZATION_STATUS_DENIED
Number
One of the possible values of the backgroundDataAuthorizationStatus property. User has explicitly denied this application from sharing data while backgrounded.
BACKGROUND_DATA_AUTHORIZATION_STATUS_NOT_DETERMINED
Number
One of the possible values of the backgroundDataAuthorizationStatus property. User has not yet made a choice with regards to this application.
BACKGROUND_DATA_AUTHORIZATION_STATUS_RESTRICTED
Number
One of the possible values of the backgroundDataAuthorizationStatus property. This application is not authorized to share data while backgrounded. The user cannot change this application’s status, possibly due to active restrictions such as parental controls being in place.
LOCATION_MANAGER_AUTHORIZATION_STATUS_AUTHORIZED
Number
One of the possible values of the locationManagerAuthorizationStatus property. User has authorized this application to share data while backgrounded.
LOCATION_MANAGER_AUTHORIZATION_STATUS_DENIED
Number
One of the possible values of the locationManagerAuthorizationStatus property. The user explicitly denied the use of location services for this application or location services are currently disabled in Settings.
LOCATION_MANAGER_AUTHORIZATION_STATUS_NOT_DETERMINED
Number
One of the possible values of the locationManagerAuthorizationStatus property. The user has not yet made a choice regarding whether this application can use location services.
LOCATION_MANAGER_AUTHORIZATION_STATUS_RESTRICTED
Number
One of the possible values of the locationManagerAuthorizationStatus property. The user cannot change this application’s status, possibly due to active restrictions such as parental controls being in place.
PERIPHERAL_MANAGER_STATE_RESETTING
Number
The connection with the system service was momentarily lost, update imminent.
PERIPHERAL_MANAGER_STATE_UNAUTHORIZED
Number
The application is not authorized to use the Bluetooth Low Energy Peripheral role.
PERIPHERAL_MANAGER_STATE_UNINITIALIZED
Number
This state is reported when the peripheral manager object maintained by the module does not (yet) exist, i.e. before initPeripheralManager is called or after BeaconsModule/releasePeripheralManager:method is called.
PERIPHERAL_MANAGER_STATE_UNSUPPORTED
Number
The platform doesn't support the Bluetooth Low Energy Peripheral role.
REGION_STATE_INSIDE
Number
One of the possible values of the state
property of the
regionStateUpdated event.
REGION_STATE_OUTSIDE
Number
One of the possible values of the state
property of the
regionStateUpdated event.
REGION_STATE_UNKOWN
Number
One of the possible values of the state
property of the
regionStateUpdated event.
Events
enteredRegion
This event is fired when the user enters a monitored region.
Note: In our testing we found this event to be unreliable. This seems to be a problem with the native SDK. We recommend to use the regionStateUpdated event instead.
Event Payload:
-
region
BeaconRegionThe region in question.
exitedRegion
This event is fired when the user exits a monitored region.
Note: In our testing we found this event to be unreliable. This seems to be a problem with the native SDK. We recommend to use the regionStateUpdated event instead.
Event Payload:
-
region
BeaconRegionThe region in question.
moduleReady
This event is fired when the module is ready. On iOS, this is a formality; On Android, you need to wait for this event before calling any methods on the module.
peripheralManagerStateChange
Fired whenever the state of the module's internal peripheral manager changes.
Event Payload:
-
state
NumberAn integer describing the state of the module's internal peripheral manager. See the PERIPHERAL_MANAGER_STATE_* constants.
peripheralWillRestoreState
Note: This event is currently not being fired, due to a limitation in Titanium. See the "iOS to iOS" sample app for a potential workaround.
Fired when iOS relaunches the app into the background (after iOS terminated it to free up resources) to complete some Bluetooth-related task. Use this event to synchronize your app's state with the state of the Bluetooth system.
See also the restoreIdentifier
parameter of the
initPeripheralManager method.
Event Payload:
-
services
Array of ServicesAn array of Service objects containing all services that were published to the local database at the time the application was terminated by the system. All the information about a service is restored, including any included services, characteristics, characteristic descriptors, and subscribed centrals.
-
advertisementData
ObjectAn object (dictionary) containing the data being advertised at the time the application was terminated by the system. See the startAdvertising method for more detail.
proximityChange
Use this event to determine which beacons have changed their proximity since the last update. This event is fired whenever the rangedBeacons event is fired, provided that the proximity of any of the ranged beacons has changed since the last rangedBeacons event.
Event Payload:
-
beacons
Array of BeaconsAn array of Beacon objects representing the beacons that changed their proximity since the last update.
rangedBeacons
Use this event to determine which beacons are in range.
See also the filterDuplicateBeacons property.
Event Payload:
-
beacons
Array of BeaconsAn array of Beacon objects representing the beacons currently in range. You can use the information in these objects to determine the range of each beacon and its identifying information.
-
region
BeaconRegionThe region object containing the parameters that were used to locate the beacons.
regionStateUpdated
This event is fired when the state of a monitored region is updated.
Event Payload:
-
region
BeaconRegionThe region object containing the parameters that were used to locate the beacons.
-
state
NumberOne of the REGION_STATE_* constants.
retrievedMonitoredRegions
Returns the result of the retrieveMonitoredRegions function.
Event Payload:
-
beaconRegions
Array of BeaconRegionsAn array of BeaconRegion objects, representing the currently monitored beacon regions.
startedAdvertising
This event returns the result of a
startAdvertising call. If advertisement could not be started, the cause will be
detailed in the errorCode
, errorDomain
, and
errorDescription
properties.
Event Payload:
-
errorCode
NumberThe error code; only present if an error occurred.
-
errorDomain
StringThe error domain; only present if an error occurred.
-
errorDescription
StringThe error description; only peresent if an