Package | com.distriqt.extension.beacon |
Class | public final class Beacon |
Inheritance | Beacon flash.events.EventDispatcher |
This class represents the Beacon extension allowing access to monitor a region and range for iBeacons.
This extension implements a cross platform solution for both Android and iOS allowing you to write code to access iBeacons on both platforms without changes.
EventsWhen the application is running the application will receive region and ranging events directly. Region exit events can take up to a minute, however an entry event should be quick (~1 second).
The application will also receive region and ranging events when in the background as long as:
If the device has been put to sleep the entry events may take a little longer but they will still be received. The ranging events will also not neccessarily be as consistent as when the application is running in the foreground.
AndroidThe manifest additions required on Android are listed below, in particular you must request permissions for using bluetooth and add in the services to receive the beacon notifications.
<manifestAdditions><![CDATA[ <manifest android:installLocation="auto"> <uses-sdk android:minSdkVersion="18" android:targetSdkVersion="18" /> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.BLUETOOTH"/> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/> <application> <service android:enabled="true" android:exported="true" android:isolatedProcess="false" android:label="iBeacon" android:name="com.distriqt.extension.beacon.services.BeaconService"></service> <service android:enabled="true" android:name="com.distriqt.extension.beacon.services.BeaconIntentProcessor"> <meta-data android:name="background" android:value="true" /> <intent-filter android:priority="1" > <action android:name="air.com.distriqt.test.DID_RANGING" /> <action android:name="air.com.distriqt.test.DID_MONITORING" /> </intent-filter> </service> </application> </manifest> ]]></manifestAdditions>
The following list are some useful tools for use during development
References:
Property | Defined By | ||
---|---|---|---|
implementation : String [read-only]
The implementation currently in use. | Beacon | ||
isSupported : Boolean [static] [read-only]
Whether the current device supports the extensions functionality
| Beacon | ||
nativeVersion : String [read-only]
The native version string of the native extension. | Beacon | ||
service : Beacon [static] [read-only]
The singleton instance of the Beacon class. | Beacon | ||
version : String [read-only]
The version of this extension. | Beacon |
Method | Defined By | ||
---|---|---|---|
Beacon()
Constructor
You should not call this directly, but instead use the singleton access
| Beacon | ||
authorisationStatus():String
Retrieves the current authorisation status. | Beacon | ||
dispose():void
Disposes the extension and releases any allocated resources. | Beacon | ||
hasAuthorisation():Boolean
Returns true if the current authorisation status is either IN_USE or ALWAYS. | Beacon | ||
init(key:String):void Deprecated: You no longer need to use an application key [static]
Initialises the extension class for use with the provided key. | Beacon | ||
isBluetoothEnabled():Boolean
Checks the current state of the bluetooth adapter. | Beacon | ||
isBroadcastAvailable():Boolean
Whether the device can act as a beacon and broadcast appropriately. | Beacon | ||
isBroadcasting():Boolean | Beacon | ||
isMonitoringRegionWithUUID(uuid:String):Boolean
Checks if there is already a monitor in process for the specified region
| Beacon | ||
requestAuthorisation(status:String):Boolean
Performs a simple operation to force the display of the permission dialog. | Beacon | ||
startBroadcast(config:BroadcastConfig):Boolean
Starts the current device broadcasting as a beacon. | Beacon | ||
startMonitoringRegionWithUUID(uuid:String, identifier:String):Boolean
This function starts monitoring a a region with the specified uuid. | Beacon | ||
stopBroadcast():Boolean
Stops the device broadcasting as a beacon. | Beacon | ||
stopMonitoringRegionWithUUID(uuid:String, identifier:String):Boolean
Stops monitoring a region for updates. | Beacon |
Event | Summary | Defined By | ||
---|---|---|---|---|
Dispatched when the user changes the authorisation status. | Beacon | |||
Dispatched when an update occurs about the available beacons. | Beacon | |||
Dispatched when the bluetooth adapter changes state to disabled. | Beacon | |||
Dispatched when the bluetooth adapter changes state to enabled. | Beacon | |||
Dispatched if there was an error when starting broadcasting | Beacon | |||
Dispatched when the broadcasting starts successfully. | Beacon | |||
Dispatched when broadcasting stops. | Beacon | |||
Dispatched when the device enters a monitored region. | Beacon | |||
Dispatched when it appears the device has exitted the region. | Beacon | |||
Dispatched when a region is started monitoring for entry and exit. | Beacon |
Constant | Defined By | ||
---|---|---|---|
EXT_CONTEXT_ID : String = com.distriqt.Beacon [static] | Beacon | ||
VERSION : String = 5.1.0 [static] | Beacon |
implementation | property |
implementation:String
[read-only]
The implementation currently in use. This should be one of the following depending on the platform in use and the functionality supported by this extension:
Android
iOS
default
unknown
public function get implementation():String
isSupported | property |
isSupported:Boolean
[read-only] Whether the current device supports the extensions functionality
public static function get isSupported():Boolean
nativeVersion | property |
nativeVersion:String
[read-only]
The native version string of the native extension.
public function get nativeVersion():String
service | property |
service:Beacon
[read-only] The singleton instance of the Beacon class.
public static function get service():Beacon
Error — If there was a problem creating or accessing the extension, or if the developer key is invalid
|
version | property |
version:String
[read-only]
The version of this extension.
This should be of the format, MAJOR.MINOR.BUILD
public function get version():String
Beacon | () | Constructor |
public function Beacon()
Constructor You should not call this directly, but instead use the singleton access
authorisationStatus | () | method |
public function authorisationStatus():String
Retrieves the current authorisation status.
ReturnsString |
dispose | () | method |
public function dispose():void
Disposes the extension and releases any allocated resources. Once this function
has been called, a call to init
is neccesary again before any of the
extensions functionality will work.
hasAuthorisation | () | method |
public function hasAuthorisation():Boolean
Returns true if the current authorisation status is either IN_USE or ALWAYS.
Retrieves the current authorisation status of this application.
There are several possible values as defined in the AuthorisationStatus
class.
Boolean — The AuthorisationStatus string
|
See also
init | () | method |
public static function init(key:String):void
Initialises the extension class for use with the provided key.
Parameters
key:String |
isBluetoothEnabled | () | method |
public function isBluetoothEnabled():Boolean
Checks the current state of the bluetooth adapter. This can be used to check if the user has disabled bluetooth on the device.
Note: On application startup this may return false even though the adapter is turned on. You should delay calls to this function until the application is up and running.
ReturnsBoolean — true if the device bluetooth is enabled powered on and false otherwise
|
isBroadcastAvailable | () | method |
public function isBroadcastAvailable():Boolean
Whether the device can act as a beacon and broadcast appropriately.
This will return false, if the device doesn't have the required OS version or it doesn't have the appropriate Bluetooth LE hardware.
Additionally it will return false if bluetooth is not enabled on the device, you should check the bluetooth enabled flag before attempting to access this flag.
ReturnsBoolean |
isBroadcasting | () | method |
public function isBroadcasting():Boolean
Returns
Boolean — Whether the device is currently broadcasting as a beacon
|
isMonitoringRegionWithUUID | () | method |
public function isMonitoringRegionWithUUID(uuid:String):Boolean
Checks if there is already a monitor in process for the specified region
Parameters
uuid:String — The UUID of the region to check
|
Boolean — true if the region is being monitored and false otherwise.
|
requestAuthorisation | () | method |
public function requestAuthorisation(status:String):Boolean
Performs a simple operation to force the display of the permission dialog.
Note on iOS this will only be shown if the authorisation status is currently NOT_DETERMINED
This allows you to control when the permission dialog is presented.
Parameters
status:String (default = NaN )
|
Boolean |
startBroadcast | () | method |
public function startBroadcast(config:BroadcastConfig):Boolean
Starts the current device broadcasting as a beacon.
The application must be running in the foreground for broadcasting to work.
Parameters
config:BroadcastConfig — The configuration to use to start broadcasting as a beacon
|
Boolean — true if the broadcast was initiated successfully, and false if it failed.
|
startMonitoringRegionWithUUID | () | method |
public function startMonitoringRegionWithUUID(uuid:String, identifier:String):Boolean
This function starts monitoring a a region with the specified uuid. Calling this function the application will start monitoring for entry and exit notifications from the specified region, including the notify entry state on display flag.
Once a region is entered the application will automatically start ranging for beacons. As ranging only works in the foreground your application will receive events only when running in the foreground.
" In general ranging only works in the foreground, but monitoring updates can happen in the background. There are two ways to configure background monitoring, and even when done properly updates can take a long time to come. Because these delays, some people mistakenly believe that monitoring in the background doesn't work. "
When the application is in the foreground, a region change detection can take ~ 1 second.
Multiple regions
If you wish to monitor multiple regions simulataneously you must make sure that
the identifier
parameter is unique for each region as well as the
uuid
! If you do not you will only receive updates for the last
region you started monitoring. The iOS SDK uses the identifier to determine
if the region is unique, and replaces any existing region monitoring if it
is the same.
Parameters
uuid:String — The UUID string for the region to start monitoring
| |
identifier:String — An identifier string to associate with this region
|
Boolean — true if monitoring was successfully started
|
stopBroadcast | () | method |
public function stopBroadcast():Boolean
Stops the device broadcasting as a beacon.
ReturnsBoolean — true if successful and false if the device wasn't broadcasting
|
stopMonitoringRegionWithUUID | () | method |
public function stopMonitoringRegionWithUUID(uuid:String, identifier:String):Boolean
Stops monitoring a region for updates.
Parameters
uuid:String — The UUID string for the region to stop monitoring
| |
identifier:String — An identifier string to associate with this region
|
Boolean — true if the region monitoring was stopped successfully
|
authorisation:changed | Event |
com.distriqt.extension.beacon.events.AuthorisationEvent
com.distriqt.extension.beacon.events.AuthorisationEvent.CHANGED
Dispatched when the user changes the authorisation status.
The status
will indicate the new authorisation status.
beacon:update | Event |
com.distriqt.extension.beacon.events.BeaconEvent
com.distriqt.extension.beacon.events.BeaconEvent.BEACON_UPDATE
Dispatched when an update occurs about the available beacons.
The beacons
will contain the list of available beacons.
bluetooth:state:disabled | Event |
com.distriqt.extension.beacon.events.BeaconEvent
com.distriqt.extension.beacon.events.BeaconEvent.BLUETOOTH_STATE_DISABLED
Dispatched when the bluetooth adapter changes state to disabled.
bluetooth:state:enabled | Event |
com.distriqt.extension.beacon.events.BeaconEvent
com.distriqt.extension.beacon.events.BeaconEvent.BLUETOOTH_STATE_ENABLED
Dispatched when the bluetooth adapter changes state to enabled.
broadcast:error | Event |
com.distriqt.extension.beacon.events.BroadcastEvent
com.distriqt.extension.beacon.events.BroadcastEvent.BROADCAST_ERROR
Dispatched if there was an error when starting broadcasting
broadcast:start | Event |
com.distriqt.extension.beacon.events.BroadcastEvent
com.distriqt.extension.beacon.events.BroadcastEvent.BROADCAST_START
Dispatched when the broadcasting starts successfully.
broadcast:stop | Event |
com.distriqt.extension.beacon.events.BroadcastEvent
com.distriqt.extension.beacon.events.BroadcastEvent.BROADCAST_STOP
Dispatched when broadcasting stops.
region:enter | Event |
com.distriqt.extension.beacon.events.BeaconEvent
com.distriqt.extension.beacon.events.BeaconEvent.REGION_ENTER
Dispatched when the device enters a monitored region. The event will contain a valid region describing the region that has been entered/discovered.
Once this event is dispatched you can expect to get updates about the beacons in the region in periodic intervals
region:exit | Event |
com.distriqt.extension.beacon.events.BeaconEvent
com.distriqt.extension.beacon.events.BeaconEvent.REGION_EXIT
Dispatched when it appears the device has exitted the region. You should stop receiving beacon update events.
region:monitoring:start | Event |
com.distriqt.extension.beacon.events.BeaconEvent
com.distriqt.extension.beacon.events.BeaconEvent.REGION_MONITORING_START
Dispatched when a region is started monitoring for entry and exit. This usually occurs almost immediately after a call startMonitoringRegionWithUUID
EXT_CONTEXT_ID | Constant |
public static const EXT_CONTEXT_ID:String = com.distriqt.Beacon
VERSION | Constant |
public static const VERSION:String = 5.1.0
The following example demonstrates the base usage of the beacon monitoring, showing the event listeners and monitoring requirements.
try { if (Beacon.isSupported) { Beacon.init( "YOUR_DEVELOPER_KEY" ); Beacon.service.addEventListener( BeaconEvent.REGION_MONITORING_START, beacon_monitoringStartHandler, false, 0, true ); Beacon.service.addEventListener( BeaconEvent.REGION_ENTER, beacon_regionEnterHandler, false, 0, true ); Beacon.service.addEventListener( BeaconEvent.REGION_EXIT, beacon_regionExitHandler, false, 0, true ); Beacon.service.addEventListener( BeaconEvent.BEACON_UPDATE, beacon_beaconUpdateHandler, false, 0, true ); Beacon.service.startMonitoringRegionWithUUID( UUID, "testing" ); } } catch (e:Error) { } ... // // EXTENSION HANDLERS // private function beacon_monitoringStartHandler( event:BeaconEvent ):void { trace( "monitoring started" ); } private function beacon_regionEnterHandler( event:BeaconEvent ):void { trace( "Entered region: " + event.region.uuid ); } private function beacon_regionExitHandler( event:BeaconEvent ):void { trace( "Exit region: " + event.region.uuid ); } private function beacon_beaconUpdateHandler( event:BeaconEvent ):void { trace( "Beacon update for region: "+event.region.uuid ); for each (var beacon:BeaconObject in event.beacons) { trace( "Beacon: "+beacon.major+"."+beacon.minor +"::"+beacon.proximity +"["+beacon.accuracy +"]"); } }