When iOS 7 was announced in 2013, one of the items on the list of new API was iBeacon. The iBeacon API became part of the CoreLocation Framework by adding to the CLLocationManager class something called “Beacon Ranging”. Just like region monitoring based on location, known as GeoFencing, Apple also uses an iBeacon (or iBeacons for multiple beacons) as a region, and thus, when you come in to range of an iBeacon your iPhone can detect this and respond accordingly.
If you understand what an iBeacon is and what to do with them, you might want to jump the initial part of this post as the tutorial is further down the page. Click here to do so.
This tutorial is based on the previous iBeacon tutorial for Objective-C that I wrote in 2013. This new tutorial is based on the newer Swift programming language (version 3 at the time of writing).
What is an iBeacon?
An iBeacon is a bluetooth transmitter that emits a signal at a number of times per second (often 100ms or 10 times per second). It uses BLE (Bluetooth Low Energy) which means that a small battery, such as a coin cell, can power a device for a month or more. Using larger batteries the charge can last a year or longer.
The iBeacon is represented in iOS as a CLBeacon which has 3 properties to identify the iBeacon and another 3 to get information about the beacon. These properties are:
Identification
1. proximityUUID
2. major
3. minor
ProximityUUID is a unique identifier that you randomly generate for your business. An example of this could be a supermarket deploying 1000’s of beacons, but each of these would use the same UUID. This UUID does not need to be registered with Apple; you just randomly generate it when you create your app and then program each of your beacons with it. I will explain a little more about proximityUUID and how it relates to “region monitoring” later on in the tutorial. [Read more…]