iBeacon advertising and scanning in a Titanium module
Objective-C Python JavaScript C
Latest commit b4a3f54 Sep 19, 2016 @jbeuckm committed on GitHub Merge pull request #41 from WillDent/master
Fixed Issue #40. when using type region of circular TiBeacon module crashes
Permalink
Failed to load latest commit information.
.settings initial commit Oct 26, 2013
Classes Merge pull request #41 from WillDent/master Sep 19, 2016
CoreBluetooth.framework initial commit Oct 26, 2013
TiBeacons.xcodeproj Added 64-bit support Jan 21, 2015
assets initial commit Oct 26, 2013
documentation add a check for ble support and Closes jbeuckm/TiBeacons#24 Oct 21, 2015
example Update app.js Jun 15, 2014
hooks initial commit Oct 26, 2013
platform initial commit Oct 26, 2013
#manifest# initial commit Oct 26, 2013
.DS_Store Added 64-bit support Jan 21, 2015
.gitignore ignoring ~ files Jul 24, 2014
.gitignore~ ignoring ~ files Jul 24, 2014
.project initial commit Oct 26, 2013
.travis.yml adding travis Jun 7, 2014
CHANGELOG.txt initial commit Oct 26, 2013
LICENSE no event when no beacons Oct 27, 2013
OrgBeuckmanTibeacons_Prefix.pch initial commit Oct 26, 2013
README.md add posibility to enable the notifyEntryStateOnDisplay functionality … Dec 9, 2015
build.py initial commit Oct 26, 2013
manifest changed versionnumber because it's breaking earlier versions of the m… Dec 10, 2015
module.xcconfig initial commit Oct 26, 2013
org.beuckman.tibeacons-iphone-0.10.0.zip dont show bluetooth warning when off Nov 2, 2015
org.beuckman.tibeacons-iphone-0.10.1.zip This resolves #17, and resolves #26 Dec 2, 2015
org.beuckman.tibeacons-iphone-0.11.0.zip changed versionnumber because it's breaking earlier versions of the m… Dec 10, 2015
org.beuckman.tibeacons-iphone-0.9.1.zip fixed crash on stopMonitoring Aug 8, 2014
org.beuckman.tibeacons-iphone-0.9.2.zip fixed crash on stopMonitoring Aug 8, 2014
org.beuckman.tibeacons-iphone-0.9.3.zip Changed SDK and titaniu.xconfig to work with 5.2.x 5.1.x Dec 12, 2015
timodule.xml example plist settings into timodule.xml Jul 24, 2014
titanium.xcconfig Changed SDK and titaniu.xconfig to work with 5.2.x 5.1.x Dec 12, 2015

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();