iBeacon Development on iOS

48
iBeacon Development on iOS Ole Begemann

description

Workshop summary: Overview about iBeacons and Bluetooth LE Region monitoring with iBeacons Proximity ranging with iBeacons New iBeacon features in iOS 8 Playing with the iBeacon infrastructure at Betahaus Common problems in working with iBeacons Slides from July 17th event at Betahaus Berlin.

Transcript of iBeacon Development on iOS

Page 1: iBeacon Development on iOS

iBeacon Development on iOSOle Begemann

Page 2: iBeacon Development on iOS

Agenda

Working with iBeacons on iOSExplore iBeacons at Betahaus

Discussion/Q&A

Page 3: iBeacon Development on iOS

What are iBeacons?

Page 4: iBeacon Development on iOS

Based on Bluetooth LEVery simplePassive

Page 5: iBeacon Development on iOS

Advertising

Permanent Advertising100–500 ms intervalsBeacons donʼt see other devices

Range: 50-100 m (5–10 m indoors)

Page 6: iBeacon Development on iOS

Beacons transmit 3 numbers

Proximity UUIDMajorMinor

Page 7: iBeacon Development on iOS

Proximity UUID

010A6F6A-DD12-4B07-A56C-EBA3BCF7136A

Usually the same for all beacons in one installation

128 bits is enough to be globally unique

Page 8: iBeacon Development on iOS

Major and Minor

0...65,535Configure in way that makes sense for your installation

Page 9: iBeacon Development on iOS

www.open-location-berlin.com

Page 10: iBeacon Development on iOS
Page 11: iBeacon Development on iOS

iBeacon APIs

Page 12: iBeacon Development on iOS

iBeacon APIs

Core Location (and not Core Bluetooth)

—Region Monitoring—Ranging

API is extremely simple

Page 13: iBeacon Development on iOS

Region Monitoring

Page 14: iBeacon Development on iOS

Region Monitoring

Detect when a beacon comes in or out of range

Monitor a single beacon or a group

Can be used in the background

Page 15: iBeacon Development on iOS

Always Check Availability and Authorization

[CLLocationManager authorizationStatus]

[CLLocationManager isMonitoringAvailableForClass: [CLBeaconRegion class]]

Page 16: iBeacon Development on iOS

CLBeaconRegion

identifierproximityUUIDmajorminor

notifyOnEntrynotifyOnExitnotifyEntryStateOnDisplay

Page 17: iBeacon Development on iOS

Region Monitoring

NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:@"F0018B9B-7509-4C31-A905-1A27D39C003C"];CLBeaconRegion *region = [[CLBeaconRegion alloc] initWithProximityUUID:uuid identifier:@"My Region"];];

[self.locationManager startMonitoringForRegion:region];

Page 18: iBeacon Development on iOS

Region Monitoring: Delegate Methods

- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region

- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region

- (void)locationManager:(CLLocationManager *)manager monitoringDidFailForRegion:(CLRegion *)region withError:(NSError *)error

Page 19: iBeacon Development on iOS

Region Monitoring

[self.locationManager stopMonitoringForRegion:region];

[self.locationManager requestStateForRegion:region];

Page 20: iBeacon Development on iOS

Proximity Ranging

Page 21: iBeacon Development on iOS

Ranging

Continuous updates (every second)

Monitor proximity and (estimated) distance

Does not work in the background

Page 22: iBeacon Development on iOS

Check Availability

[CLLocationManager isRangingAvailable]

Page 23: iBeacon Development on iOS

Proximity Ranging

[self.locationManager startRangingBeaconsInRegion:region];

[self.locationManager stopRangingBeaconsInRegion:region];

Page 24: iBeacon Development on iOS

Proximity Ranging: Delegate Methods

- (void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region

- (void)locationManager:(CLLocationManager *)manager rangingBeaconsDidFailForRegion:(CLBeaconRegion *)region withError:(NSError *)error

Page 25: iBeacon Development on iOS

CLBeacon

proximityUUIDmajorminor

proximityaccuracyrssi

Page 26: iBeacon Development on iOS

proximity

CLProximityImmediate (centimeters)CLProximityNear (< 2–3 m)CLProximityFarCLProximityUnknown

Page 27: iBeacon Development on iOS

accuracy

“Indicates the one sigma horizontal accuracy in meters. Use this property to differentiate between beacons with the same proximity value. Do not use it to identify a precise location for the beacon.”

Not a distance estimate!

Page 28: iBeacon Development on iOS

rssi

Received signal strengthMeasured in decibels

Page 29: iBeacon Development on iOS

Demos

Page 30: iBeacon Development on iOS

MuseumUses ranging to display information about a piece of art when the associated beacon is in immediate or near proximity.

Page 31: iBeacon Development on iOS

BEACONinsidegithub.com/beaconinside/BEACONinside-SDK-iOS

Uses the BEACONinside SDK(built on top of Core Location APIs)

Page 32: iBeacon Development on iOS

oleb.net/files/ibeacon-workshop.zip

Page 33: iBeacon Development on iOS

Common Problems

Page 34: iBeacon Development on iOS

Region Monitoring

Region Exit is not immediate (15 seconds or more)

Enter and Exit events can take up to 15 minutes in the backgroundregion.notifyEntryStateOnDisplay = YES

http://developer.radiusnetworks.com/2013/11/13/ibeacon-monitoring-in-the-background-and-foreground.html

Page 35: iBeacon Development on iOS

Ranging

Intermittent signal loss

Signal strength is not a reliable measure for distance

Apps should apply signal smoothing

Page 36: iBeacon Development on iOS

Creating iBeacons

Page 37: iBeacon Development on iOS

Turn your device into a beacon

CLBeaconRegion *region = [[CLBeaconRegion alloc] initWithProximityUUID:... major:... minor:... identifier:...]];NSDictionary *peripheralData = [region peripheralDataWithMeasuredPower:nil];self.peripheralManager = [[CBPeripheralManager alloc] initWithDelegate:self queue:nil];[self.peripheralManager startAdvertising:peripheralData];

Page 38: iBeacon Development on iOS

Core Bluetooth

Page 39: iBeacon Development on iOS

Core Bluetooth

Used to actively connect to Bluetooth LE devices

Devices offer services and characteristics

Not required for iBeacons, but many iBeacons offer additional functionality via Core Bluetooth

Page 40: iBeacon Development on iOS

Agenda

Working with iBeacons on iOSExplore iBeacons at Betahaus

Discussion/Q&A

Page 41: iBeacon Development on iOS

Agenda

Working with iBeacons on iOSExplore iBeacons at Betahaus

Discussion/Q&A

Page 42: iBeacon Development on iOS

Limitations on iOS

Scanning for beacons with unknown UUIDs is not possible

Page 43: iBeacon Development on iOS

App Store Policy

Not permitted to expose UUIDs to users

Makes it difficult to write apps that work with the userʼs own beacons

Page 44: iBeacon Development on iOS
Page 45: iBeacon Development on iOS

Documentation

Page 46: iBeacon Development on iOS

developer.apple.com/ibeacon/

Page 47: iBeacon Development on iOS

Thank you@olebegemann

[email protected]

oleb.net

Page 48: iBeacon Development on iOS