Tuesday, April 15, 2014

iBeacon Hands On - Transmitter & Scanner Part

Finally decided to implement the details acquired into an app.

There are two parts for this app. One, Beacon Tranmittor and next part is Beacon Monitor.

- Created a Single View application
- included CoreLocation, CoreBluetooth frameworks to it.
- Created a class BeaconTransmitter
- Created CLBeaconRegion object to create the beacon region for transmission
- Created a NSDictionary to hold the peripheral properties of this beacon
- Created a CBPeripheralManager instance to create get the delegates for peripheral start and stop. This is used for start and stop of advertising respectively.

Implemented the CBPeripheralManagerDelegate to get the peripheral updates. in the peripheral update when the event is CBPeripheralManagerStatePoweredOn, startAdvertising the beacon using peripheral manager startAdvertising api by passing the beacon properties dictionary.  Similarly, when the state is powered off, we should stop the advertising.


For the Beacon Monitoring part, the main two classes required are

. CLLocationManager
- CLBeaconRegion

first need to create an instance of CLLocationManager and set the delegate and override the didEnterRegion and didExitRegion methods mainly. We also need to initiate the CLBeaconRegion object and give the uuid as the known uuid of the beacon . say for e,g. the uuid given in the above trasmitting part. also the same identifier can be given as well. to start monitoring for region, core location manager instance created has a method startMonitoringForRegion. When the didEnterRegion is called back, the code can search for ranging the beacon with the given identifiers specificatlly using startRangingBeaconsInRegion. Similarly when the didExitRegion is called back, code can stop ranging the beacons. When the specific beacon is ranged, the didRangeBeacons method will be called back. We get a set of beacons in this call back and one can decide based on number of factors such as proximity, rssi strength etc.

Below is my observation on the whole application

- If the transmitter is a phone, when the screen locks up, the device which is monitoring for this transmitter receives didExitRegion callback. This makes the app to be available always in foreground. This is kind of a restriction. But assuming in the realworld, it may be some other device that is acting as a transmitter

- When the call back didRangeBeacon comes into the app, it keeps coming. But if kill the app and launch again, even though other transmitter is still transmitting, the didRangeBeacon doesnt come to the app.





No comments:

Post a Comment