Monday, April 21, 2014

iBeacon - Data Exchange after Ranging

iBeacons are transmit only devices and not the ones for exchanging data.

For exchanging data between two devices once the ranging is done, there are two approaches that can be followed

- Use CoreBluetooth framework
- Use Webservices and polling
- Using SIP services

The WebService way is a bit cumbersome as it involves the polling mechanism. Below is the procedure during the entire operation of the app.

- A detects that B is in range
- A writes to a webservice where B constantly reading.

This model involves B to constantly poll the service and it is bit overhead on network and devices.

Using the CoreBluetooth is a better approach as both the devices getting identified will have the Bluetooth on. However, only problem is that the type of data and the capability of device to support that profile may vary between device.

Using SIP is another option as the communication will look almost real time. When the beacon is in range, make a sip MESSAGE request and do the communication.

To get some more details on when the data operations are to be done. below are the three delegate methods iOS provides for this purpose

1. locationManager:didDetermineState:forRegion
2. locationManager:didEnterRegion:
3. locationManager:didExitRegion:

the locationManager:didDetermineState:forRegion is getting called always along with the #2,#3 methods. in this method, the below code can be used to determine whether the app entered into the region.

if(state == CLRegionStateInside)
    {
        notification.alertBody = NSLocalizedString(@"You're inside the region", @"");
    }
    else if(state == CLRegionStateOutside)
    {
        notification.alertBody = NSLocalizedString(@"You're outside the region", @"");

    }

The advantage of this method is that it get called in multiple situations:

1. This method gets called whenever didEnterRegion or didExitRegion is getting called. So it can be used in place of this
2. This method is getting called when requestStateForRegion method is called to get the state
3. If an iBeacons's property notifyEntryStateOnDisplay is set, then also this method is called even if the app is not running to notify that the region state is determined.



1 comment:

  1. Love it! Thank you so much for sharing this one really well defined all peaceful info regarding iBeacon BLE Device,I Really like it- ibeacon app development | ibeacon application development

    ReplyDelete