Beacons implementation for iOS in Titanium
Posted By : Akshay Luthra | 30-Dec-2014
Beacon(or, iBeacon) is Bluetooth low-energy (BLE) wireless technology to create a different way of providing location-based information and services to iPhones and other iOS devices.
The beacons themselvers are small, cheap Bluetooth transmitters. Apps installed on your iPhone listen out for the signal transmitted by these beacons and respond accordingly when the phone comes into range.
To use iBeacon, you need iOS 7 or later, Bluetooth turned on, and a compatible iOS device:
iPhone 4s or later
iPad (3rd generation) or later
iPad mini or later
iPod touch (5th generation) or later
Each iBeacon has 3 entries to distinguish them -
UUID
Major ID
Minor ID
The UUID is an unique identifier. For example, if Big Bazaar decides to deploy beacon sensors inside its store and make an app that can tell the user once they arrive at a specific store, they would define a UUID that is unique to their app and the beacons inside their stores. Inside the stores, they would place beacon devices and configure each of them to use a different “minor” value. For example, at the store A, they would place all beacon devices broadcasting the Starbucks UUID, major value 0, minor 1 near the door, minor 2 near the mugs display and minor value 3 near the cashier. At store B, they would use the same UUID, but major 1 and minor values according to the location inside the store.
Now to implement the Beacons functionality for iOS in Titanium, you need to download the latest module from the link "http://gitt.io/component/org.beuckman.tibeacons" and include that module in your "tiapp.xml" .
Then in your "app.js" file write the code -
// this sets the background color of the master UIView Titanium.UI.setBackgroundColor('#000'); var TiBeacons = require('org.beuckman.tibeacons'); var win = Ti.UI.createWindow({ backgroundColor : '#fff' }); TiBeacons.startMonitoringForRegion({ uuid : < your beacon UUID >, identifier : < your beacon Identifier >, major : < your beacon major >, minor : < your beacon minor >, }); TiBeacons.addEventListener("enteredRegion", function(e) { Ti.API.info("enteredRegion" + JSON.stringify(e)); }); TiBeacons.addEventListener("exitedRegion", function(e) { Ti.API.info("exitedRegion" + JSON.stringify(e)); }); TiBeacons.addEventListener("determinedRegionState", function(e) { Ti.API.info("determinedRegionState" + JSON.stringify(e)); if (e.regionState == "inside") { alert("You are inside your Beacon Range"); } }); // look for iBeacons TiBeacons.startRangingForBeacons({ uuid : < your beacon UUID >, identifier : < your beacon Identifier >, major : < your beacon major >, minor : < your beacon minor >, }); win.open();
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Akshay Luthra
Akshay Luthra has excellent experience in developing Cross Platform Mobile Apps using JavaScript and Titanium Framework. He loves listening to music and travelling new places.