featured-image-ios

How to Manage iBeacon Scanning in iOS using Mesosfer – Part 2

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

Table of Contents

  1. 1. Tutorial (Continued)
    1. 1.1. Define beacon cloud data
    2. 1.2. Preparation
    3. 1.3. Download and scan beacon
    4. 1.4. Manage scanning results

1. Tutorial

This tutorial was the 2nd part of How to Manage iBeacon Scanning in iOS using Mesosfer.

1.1. Define beacon cloud data

Go to your Mesosfer app -> Base -> Beacon, add this beacon below :

You can also define your own beacon parameters to match beacon device you have.

1.2. Preparation

Before downloading beacons data, we need to setup some property :

  1. CBBluetoothManager. This is the entry point to the bluetooth role management like checking bluetooth state, check whether the device is capable of using Bluetooth Low Energy, showing dialog to turn on the bluetooth, etc.
  2. CBBeaconManager. This is the entry point to beacon scanning service like checking authorization status, setting region for scanning, starting and stopping ranging beacons, monitoring beacons, etc.
  3. We need to implement CBBluetoothManagerDelegate and CBBeaconManagerDelegate too.

Add these lines below to the interface of AppDelegate :

Initialize bluetooth and beacon manager within method application:didFinishLaunchingWithOptions :

After initializing bluetooth manager and set the delegate, we need to implement the method :

These line above mean that when bluetooth state is already ON, it will call in beacon manager to request authorization to use the location service. As we know that, beacon scanning services are within iOS Core Location Framework. So we need to enable location service and request authorization to use it.

1.3. Download and scan beacon

After authorizing the request for a location service use, the bluetooth manager will call the delegate method didChangeAuthorizationStatus:

So now we can download beacon data from Mesosfer Cloud and then start the monitoring for beacon regions.

1.4. Manage scanning results

Having the list pre-sorted by the Cubeacon SDK, and with all the prep work we’ve performed, the monitoring listener turns out to be quite simple :

The complete code for AppDelegate class :

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

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.