featured-image-ios

How to Manage iBeacon Scanning in iOS using Mesosfer

This tutorial is about How to Manage iBeacon Scanning in iOS using Mesosfer.

Table of Contents

  1. 1. iBeacon
    1. 1.1. What is iBeacon?
    2. 1.2. Cubeacon SDK for scanning beacon
    3. 1.3. Beacon region
    4. 1.4. Ranging beacons
    5. 1.5. Monitoring regions
  2. 2. Mesosfer – Beacon Module
    1. 2.1. Storyline
    2. 2.2. Presence
    3. 2.3. Notification
    4. 2.4. Microlocation
  3. 3. Tutorial
    1. 3.1. Create Mesosfer App
    2. 3.2. Create project
    3. 3.3. Installing library & framework
    4. 3.4. Intialize Cubeacon & Mesosfer SDK

Integrating Cubeacon and Mesosfer SDK for iOS. This tutorial describes :

  1. How to manage beacon scanning in iOS applications.
  2. Demonstrates how to use existing Beacon module in Mesosfer SDK.
  3. It also demonstrates the usage of the Beacon analytic which allows developers to send log asynchronously.

The tutorial is based on Xcode 8.2.1 and iOS SDK 10.2. Testing device using iOS device with iOS version 8.0, Bluetooth Low Energy enabled and some beacon.


1. iBeacon

1.1. What is iBeacon?

iBeacon is a protocol developed by Apple and introduced at the Apple Worldwide Developers Conference in 2013. Various vendors have since made iBeacon-compatible hardware transmitters – typically called beacons – a class of Bluetooth low energy (BLE) devices that broadcast their identifier to nearby portable electronic devices. The technology enables smartphones, tablets and other devices to perform actions when in close proximity to an iBeacon.

iBeacon is an exciting technology enabling new location awareness possibilities for apps. Leveraging Bluetooth Low Energy (BLE), a device with iBeacon technology can be used to establish a region around an object. This allows a smartphone to determine when it has entered or left the region, along with an estimation of proximity to a beacon . There are both hardware and software components to consider when using iBeacon technology.

An iBeacon advertisement provides the following information via Bluetooth Low Energy:

Field Size Description
UUID 16 bytes Application developers should define a UUID specific to their app and deployment use case.
Major 2 bytes Further specifies a specific iBeacon and use case. For example, this could define a sub-region within a larger region defined by the UUID.
Minor 2 bytes Allows further subdivision of region or use case, specified by the application developer.

1.2. Cubeacon SDK for scanning beacon

Cubeacon SDK for iOS is a framework to allow interaction with any beacons. The SDK system requirements are iOS 8.0 or above and Bluetooth Low Energy.

Cubeacon SDK allows for:

  • Beacon ranging (scans beacons and optionally filters them by their properties).
  • Beacon monitoring (monitors regions for those devices that have entered/exited a region).

You can read more about Cubeacon SDK for iOS here.

1.3. Beacon region

Beacon region is like a filter or a regular expression. Each beacon is identified by three values:

  1. Proximity UUID, most commonly represented as a string, e.g. CB10023F-A318-3394-4199-A8730C7C1AEC.
  2. Major, an unsigned short integer, i.e., an integer ranging from 1 to 65535, (0 is a reserved value).
  3. Minor, also an unsigned short integer, like the major number.

1.4 Ranging beacons

Ranging beacons is an actions that triggered based on proximity to a beacon; works only when the app is running (e.g., it’s displayed on screen, or running in the background in response to a monitoring event, etc.)

1.5. Monitoring regions

Monitoring regions is an actions that triggered on entering/exiting region’s range; works no matter whether the app is running or suspended. It’s important to remember that Monitoring allows you to scan for beacon regions, while Ranging is for interacting with individual beacons.

2. Mesosfer, Beacon Module

Beacon module is one of Mesosfer module that has specific feature to manage beacon activities.

2.1. Storyline

This module used for showing a “story” when beacons are detected or in range e.g. museum, merchant shop, etc. Y0u can manage what “story” that need to show to the end users when detected beacon e.g. some alert text or notification, displaying an image campaign, playing a video campaign or maybe open some website. You can also choose when the “story” must displayed based on beacon’s event :

  • Enter, triggered when user entering region of a beacon
  • Exit, triggered when user exiting region of a beacon
  • Immediate, triggered when user range approximately <1 meter from beacon
  • Near, triggered when user range approximately within 1-3 meters from beacon
  • Far, triggered when user range approximately >3 meters from beacon

Besides, you can select what days to show when “story” was triggered. By using a storyline, you can manage multiple beacon’s “story”.

2.2. Presence

This module can be used to tracking any check-in and check-out data e.g. employee attendance, student presence, etc.

2.3. Notification

This module is the simple version of storyline, it can only manage a beacon for each notification e.g. show a greeting when user entering shop.

2.4. Microlocation

This module can be used for track indoor location using a mapped beacon in an area.

3. Tutorial

3.1. Create Mesosfer app

First, you need to login or register to Mesosfer Cloud. Then create an app with type Beacon :

Create-Mesosfer-App-With-Beacon

Execute the button Make It!.

3.2. Create project

Open Xcode, choose File -> New -> Project -> Single View Application. Type Product Name: Cubeacon, use Organization Identifier: com.eyro.Mesosfer. You can choose the Language between Objective-C or Swift. Execute the Next button, then choose where you want to save this project and save.

3.3. Installing library and frameowk

First, we need to ensure the following frameworks and a library exist in your project :

  • CoreLocation.framework
  • CoreBluetooth.framework
  • libsqlite3.0.tbd

Then, we can install Cubeacon & Mesosfer framework like below :

Cubeacon SDK for iOS :

  • Downloade latest SDK from here.
  • Extract cubeacon.zip file.
  • Drag and drop cubeacon.framework into Frameworks section of your Xcode project

Mesosfer SDK for iOS :

  • Download the latest SDK from here.
  • Copy mesosfer.zip file.
  • Drag and drop mesosfer.framework into Frameworks section of your Xcode project

Open your project settings and go to the Capabilities tab. Enable these modes Background Mode :

  • Location updates
  • Uses Bluetooth LE accessories
  • Background fetch

Add this two lines into info.plist file :

1st Key NSLocationAlwaysUsageDescription
Type String
Value $(PRODUCT_NAME) use location service to scan nearby beacons
2nd Key NSLocationWhenInUseUsageDescription
Type String
Value $(PRODUCT_NAME) use location service to scan nearby beacons in foreground
3rd Key NSBluetoothPeripheralUsageDescription
Type String
Value $(PRODUCT_NAME) use bluetooth to scan nearby beacons

3.4. Initialize Cubeacon & Mesosfer SDK

To initialize Cubeacon and Mesosfer SDK, add the following initialization code in AppDelegate application:didFinishLaunchingWithOptionsmethod :

IMPORTANT: Change Mesosfer application id and client key with your own credentials.

It’s done. We will continue this tutorial on Part-2.

Lead Mobile Software Engineer. Having more than 8 years in IT Consultant. Love working with new mobile platform technology. Expert in Android and iOS Mobile Development.