What is iBeacon?
iBeacon is a Bluetooth advertising protocol (“packet”) designed by Apple. Apple’s own introduction to iBeacon is available at developer.apple.com/ibeacon.
iBeacon has native, built-in support in iOS, via the iOS Location Services and the Core Location framework. The Core Location API allows you to detect nearby iBeacon devices, as well as listen for enter/exit events, fired when the user enters and exits range of an iBeacon device.
Here’s how Core Location compares to Estimote’s Proximity SDK:
Estimote Proximity SDK Estimote/iOS-Proximity-SDK Estimote/Android-Proximity-SDK | Core Location | |
---|---|---|
packets used | Estimote Monitoring | iBeacon |
Estimote Cloud services - attachments - analytics - telemetry | yes | - |
trigger range | configurable via an API parameter (with advanced RSSI processing for better accuracy) | unspecified (anywhere in range) |
"exit" event delay | up to a few seconds | at least 30 seconds |
background monitoring | unlimited | max. 20 regions |
security | yes | - |
Tutorial | Docs |
If you want to start building, head on to one of the tutorials. For more information about iBeacon itself, read on!
Info: For completeness, let’s also mention the “monolithic” Estimote SDK, from Estimote/iOS-SDK, which supports both iBeacon and Estimote Monitoring detection. However, the proximity detection features in that SDK are now obsoleted in favor of the Estimote Proximity SDK.
If you’re starting a new integration or deployment, we recommend the Proximity SDK.
What’s ahead (aka Table of Contents)
- iBeacon, beacon, what’s the difference?
- UUID, major, minor, and Beacon Regions
- Monitoring and Ranging
- Configure Estimote Beacons to broadcast iBeacon
iBeacon, beacon, what’s the difference?
“Bluetooth beacons” is a general term for Bluetooth peripherals which advertise their presence to other Bluetooth devices nearby. Bluetooth devices can be detected on iOS via the Core Bluetooth framework.
iBeacon is just an advertising protocol—a specification from Apple that tells what data, and in what format, a Bluetooth beacon needs to advertise. iBeacon-enabled hardware can then be used with iOS Location Services and the Core Location framework. iBeacon packets cannot be detected via Core Bluetooth.
All in all, you can think about iBeacon as specialized beacon advertising, which makes it work with iOS Location Services.
Estimote Beacons are fully iBeacon-compatible.
UUID, major, minor, and Beacon Regions
Full iBeacon protocol specification is available on developer.apple.com/ibeacon, in the “Artwork and Specifications” section.
Most of the iBeacon packet is a 3-part identifier of the beacon, and these parts are:
- UUID, 16 bytes, usually represented as a string, e.g., “B9407F30-F5F8-466E-AFF9-25556B57FE6D”
- Major number, 2 bytes, or an “unsigned short”, i.e., a number from 1 to 65,535
- Minor number, 2 bytes, same as Major
Such design of the identifier allows building hierarchies of beacons, which is especially handy when building large beacon networks.
Imagine deploying beacons in all Estimote offices. An example hierarchy could be:
UUID E6FA79C7-804F-4742-863B-BD4D282ED9BA = common UUID for all our beacons
├ major 1 = all "lobby" beacons
│ ├ minor 1 = "lobby" beacons in the KRK office
│ ├ minor 2 = "lobby" beacons in the NYC office
│ └ minor 3 = "lobby" beacons in the SF office
├ major 2 = all "watercooler" beacons
│ ├ minor 1 = "watercooler" beacons in the KRK office
│ └ ...
└ ...
Now, this is where Beacon Regions (CLBeaconRegion
) come into play. You can think about them as a special type of “geofences,” except they’re defined by being in range of beacons with matching UUIDs, majors, and minors, and not by GPS coordinates.
For example, with the hierarchy above, we can define two Beacon Regions:
let uuid = UUID(uuidString: "E6FA79C7-804F-4742-863B-BD4D282ED9BA")!
let r1 = CLBeaconRegion(proximityUUID: uuid, major: 1, identifier: "lobby")
let r2 = CLBeaconRegion(proximityUUID: uuid, major: 2, identifier: "watercooler")
This way, whenever somebody enters the range of lobby or watercooler beacons, no matter which office (note that we omitted the minor numbers), our app can know about it.
Monitoring and Ranging
Once you’ve defined the Beacon Regions, there are two ways you can use them:
-
Monitoring
- start:
func startMonitoring(for region: CLBeaconRegion)
- delegates:
didEnterRegion region: CLBeaconRegion
,
didExitRegion region: CLBeaconRegion)
,
didDetermineState state: CLRegionState, for region: CLBeaconRegion
- required Location Services authorization level: “always”
-
This will let your app know whether you’re inside or outside the Beacon Region (as defined by being in range of beacons with matching UUID/major/minor), and whenever that state changes.
iOS will keep monitoring on the app’s behalf even when the app stops running or gets killed. As soon as an enter or exit event happens, iOS will launch the app into the background for a few seconds to handle the event. You can e.g. show a notification to prompt to open the app, send some data to your server, or start ranging for a short period of time to learn the exact majors/minors of beacons in range.
- start:
-
Ranging
- start:
func startRangingBeacons(in region: CLBeaconRegion)
- delegate:
didRangeBeacons beacons: [CLBeacon], in region: CLBeaconRegion
- required Location Services authorization level: “when in use”
-
Every 1 second, iOS will deliver a full list of beacons (matching the region) which are detected nearby.
Ranging only works when the app is running, i.e., either shown on screen, on already running in the background. However, ranging itself can not keep the app active in the background, or launch the app into the background like Monitoring does.
- start:
Configure Estimote Beacons to broadcast iBeacon
Every Estimote Beacon ever shipped supports the iBeacon packet. You can check if it’s enabled (and if not, enable it) via the “Estimote” app, available on the App Store. Go to the Configuration section, find your beacon on the radar, wait till the app connects to it, and go to the Broadcasting section.
The app will also allow you to change the UUID, major, and minor broadcast by the beacon, as well as the advertising interval and transmit power with which the iBeacon packet is broadcast.
Keep in mind: While we allow customizing the advertising interval for the iBeacon packet in Estimote Beacons, the iBeacon specification requires it to be 100 ms for full compatibility!