iBeacon: Guide to Action



    iBeacon is a new technology that is built on the basis of Bluetooth Low Energy or BLE. So far, iBeacon is most associated with Apple. Since 2013, iBeacon has been integrated into Apple iOS 7. For the first time, a pilot project was launched in Apple stores in December 2013 and a significant expansion of the use of technology is expected in 2014 - via Wi-Life

    Good afternoon, dear Habrahabr!

    Today we will get acquainted with the implementation of the BLE functionality for iOS based on iBeacon devices from Roximity . I searched, asked, asked, and, as it were, nobody wrote about the practical side of the issue in Runet. I share the article in two parts: about setting up on Roximity servers and about hood applications.

    Interested please under cat.

    Magic on the side of Roximity


    After purchasing the bacon, you will be given a “Merchant Login”. I got three bacon; Here is the first page of the Bacon admin panel:



    Before moving on, it is worth noting that:

    • An unlimited number of tags can be assigned to each bacon.
    • Multiple bacon tags can be assigned the same tag.
    • You can create messages that will pop up on a specific action (entrance to the coverage area, exit from it, immediate proximity)
    • Messages can be assigned to specific tags.
    • If the message is assigned to a tag that belongs to several bacon, then these bacon work as one large bacon

    The form for creating a message is as follows:



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

    • The name of the message that does not shine anywhere except this admin area
    • The action by which the message is triggered
    • The message itself that the user sees
    • Frequency of occurrence
    • Post-related bacon tags
    • Message End Date

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



    The magic is on our side


    Interestingly, bacon works not only when the application is active, but also in the background, and even when closed! That is, if you have installed the application with the Roximity SDK, then every time your bacon appears in the phone’s visibility, your application will open for 30 seconds by calling the appropriate methods from the Background Fetch opera.

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

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

    An example handleNotification: method 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 lost the memo of the corresponding definitions. I remind you that handleNotification: will be called even if your application was completely closed!

    Conclusion


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

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

    Ready to answer all your questions!

    Also popular now: