📜 ⬆️ ⬇️

iBeacon: Guide to Action



iBeacon is a new technology based on Bluetooth Low Energy or BLE. While iBeacon is most associated with Apple. Starting in 2013, iBeacon is built into Apple iOS 7. For the first time, a pilot project was launched in Apple stores in December 2013 and in 2014 a significant increase in the use of technology is expected - via Wi-Life

Good afternoon, dear Habrahabr!

Today we will get acquainted with the implementation of BLE functionality for iOS based on Roximity iBeacon devices. I searched, asked, whispered, sort of like, no one ever wrote about the practical side of the issue in runet. I divide the article into two parts: about setting up on Roximity servers and about engine rooms of applications.
')
Interested please under the cat.

Roximity magic


After buying the bacon, they give you a “Merchant Login”. I purchased three bacons; This is the first page of the bacon admin panel:



Before going further, it is worth noting that:


The form for creating a message is as follows:



Nearby is a memo about the approximate radius of operation of key fobs. Each message can be assigned:


When the messages are configured, we download the SDK, embed them in the application, and move on to the next part of the article. The SDK is quite young and updated with stable frequency.



Magic is on our side


Interestingly, the bacon works not only when the application is active, but also in the background, and even closed state! That is, if you have an application installed with the Roximity SDK, then each time your bacons appear in the phone's visibility, your application will open for 30 seconds with a call to the appropriate methods from the Background Fetch opera.

After properly installing the Roximity SDK, the Roximity server will do absolutely everything for you. The only thing we need to do (if at all) is to subscribe to ROX_NOTIF_MESSAGE_FIRED :

[[NSNotificationCenter defaultCenter] addObserver:sharedManager selector:@selector(handleNotification:) name:ROX_NOTIF_MESSAGE_FIRED object:nil]; 

An example method of handleNotification: might look like this:

 - (void)handleNotification:(NSNotification *)rawNotification { NSDictionary *notification = rawNotification.userInfo; NSString *beaconId = notification[@"com.roximity.notif"][@"com.roximity.notification.trigger"][@"beaconId"]; NSString *event = notification[@"com.roximity.notif"][@"com.roximity.notification.trigger"][@"event"]; NSString *name = notification[@"com.roximity.notif"][@"com.roximity.notification.trigger"][@"name"]; NSLog(@"Beacon event: %@ - %@ - %@", event, beaconId, name); } 

I apologize for the magic lines, unfortunately, I have lost the memo on the relevant definitions. I remind you that handleNotification: will be called even if your application has been completely closed!

Conclusion


That's all! Use bacon for health and never be afraid to dip into new technologies.

If you find any inaccuracies or typographical errors in the article, be sure to write in my habracenter.

Ready to answer all your questions!

Source: https://habr.com/ru/post/226037/


All Articles