Hardware Reference
In-Depth Information
Implementing an iBeacon App
To implement the following iBeacon app, all you need is the Core Location framework,
within which the key class references for the application include
CLLocationManager
,
CLBeaconRegion
, and
CLBeacon
. No parts of the Core Bluetooth framework are used
directly. This iPhone app detects the presence of nearby beacons and determines which
one is closest.
To test the app, we programmed several BLE112 modules (shown in
Figure 9-4
), pow‐
ered by CR2032 coin cells for easy placement.
Figure 9-4. BLE112 modules programmed as iBeacons and powered by CR2032 coin
cells.
For testing, the Bluegiga BLE112 modules generated and transmit‐
ted the required iBeacon advertisng packet. Complete code for both
the iPhone app and the testing program for the BLE112 modules is
provided in the
GitHub repository for this topic
.
First, you need to create and register the beacon region:
@implementation
BobsBeaconTracker
-
(
instancetype
)
init
{
self
=
[
super
init
];
if
(
self
==
nil
)
return
nil
;
self
.
locationManager
=
[[
CLLocationManager
alloc
]
init
];
self
.
locationManager
.
delegate
=
self
;