iBeacon advertising and scanning in a Titanium module
Objective-C Python JavaScript C
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.settings
Classes
CoreBluetooth.framework
TiBeacons.xcodeproj
assets
documentation
example
hooks
platform
#manifest#
.DS_Store
.gitignore
.gitignore~
.project
.travis.yml
CHANGELOG.txt
LICENSE
OrgBeuckmanTibeacons_Prefix.pch
README.md
build.py
manifest
module.xcconfig
org.beuckman.tibeacons-iphone-0.10.0.zip
org.beuckman.tibeacons-iphone-0.10.1.zip
org.beuckman.tibeacons-iphone-0.11.0.zip
org.beuckman.tibeacons-iphone-0.9.1.zip
org.beuckman.tibeacons-iphone-0.9.2.zip
org.beuckman.tibeacons-iphone-0.9.3.zip
timodule.xml
titanium.xcconfig

README.md

Usage

See this example app for usage: TiBeacons Example App

Become an iBeacon:

var TiBeacons = require('org.beuckman.tibeacons');

TiBeacons.addEventListener("advertisingStatus", function(event) {
    Ti.API.info(event.status);
});

TiBeacons.startAdvertisingBeacon({
   uuid : "00000000-0000-0000-0000-000000000000",
   identifier : "TiBeacon Test",
   major: 1,
   minor: 2
});

Start monitoring for iBeacons in one or more regions. This will continue in the background if the proper UIBackgroundModes are listed in tiapp.xml. Once the app has run once, iOS will start your app and run the event handler if it finds one of the monitored regions. The app does not have to be running.

TiBeacons.startMonitoringForRegion({
    uuid : "00000000-0000-0000-0000-000000000000",
    identifier : "Test Region 1",
});

TiBeacons.startMonitoringForRegion({
    uuid : "00000000-0000-0000-0000-000000000001",
    identifier : "Test Region 2 (group-specific)",
    major: 1
});

TiBeacons.startMonitoringForRegion({
    uuid : "00000000-0000-0000-0000-000000000002",
    identifier : "Test Region 3 (device-specific)",
    major: 1,
    minor: 2
});

// To stop monitoring one single region
TiBeacons.stopMonitoringRegion({
    uuid : "00000000-0000-0000-0000-000000000002",
    identifier : "Test Region 3 (device-specific)",
    major: 1,
    minor: 2
});

// To monitor regions and get notified on awake the iPhone
TiBeacons.startMonitoringRegion({
    uuid : "00000000-0000-0000-0000-000000000002",
    identifier : "Test Region 3 (device-specific)",
    major: 1,
    minor: 2,
    notifyEntryStateOnDisplay: "YES" 
});

// To stop monitoring all regions
TiBeacons.stopMonitoringAllRegions();

// Make sure you stopped ranging all beacons after stop monitoring 
TiBeacons.stopRangingForAllBeacons();

Listen for region events:

TiBeacons.addEventListener("enteredRegion", alert);
TiBeacons.addEventListener("exitedRegion", alert);
TiBeacons.addEventListener("determinedRegionState", alert);

Start ranging beacons in a region. This takes takes more energy and will report the approximate distance of the device to the beacon.

TiBeacons.startRangingForBeacons({
    uuid : "00000000-0000-0000-0000-000000000002",
    identifier : "Test Region",
    major: 1, //optional
    minor: 2 //optional
});

Listen for the range events:

TiBeacons.addEventListener("beaconRanges", function(event) {
   alert(event.beacons);
});

Or just listen for beacon proximity changes:

TiBeacons.addEventListener("beaconProximity", function(e){
   alert("beacon "+e.major+"/"+e.minor+" is now "+e.proximity);
});

Permission and Hardware Status

Get notified when the user allows or disallows location services for your app:

TiBeacons.addEventListener("changeAuthorizationStatus", function(e){
   if (e.status != "authorized") {
      Ti.API.error("not authorized");
   }
});

Find out if Bluetooth Low Energy is supported on the current device:

if (TiBeacons.isBLESupported()) {
  Ti.API.error("BLE is supported on this device");
} else {
  Ti.API.error("BLE isn't supported on this device");
]

Find out if bluetooth is on or off (or unauthorized or unsupported or resetting):

TiBeacons.addEventListener("bluetoothStatus", function(e){
   if (e.status != "on") {
      Ti.API.error("bluetooth is not on");
   }
});

TiBeacons.requestBluetoothStatus();