Bluetooth 4.0 and iBeacons in your iOS app - Francesco Novelli - Codemotion Milan 2014

39
MILAN november 28 th /29 th , 2014 Bluetooth 4.0 and iBeacons in your iOS app [email protected] - RunCode @if9 runcode.it Francesco Novelli

description

With iOS 7 Apple introduced iBeacons. It's a new API based on Bluetooth 4.0 called Bluetooth Low Energy. In this we will see how everyone can use iBeacons to create great iOS app, also if you aren't an hardware guy. A small part of the talk will explain how to use CoreBluetooth framework to connect to BLE devices. After this talk you will be able to use Bluetooth 4.0 easily in you app.

Transcript of Bluetooth 4.0 and iBeacons in your iOS app - Francesco Novelli - Codemotion Milan 2014

Page 1: Bluetooth 4.0 and iBeacons in your iOS app - Francesco Novelli - Codemotion Milan 2014

MILAN november 28th/29th, 2014

Bluetooth 4.0 and iBeacons in your iOS [email protected] - [email protected]

Francesco Novelli

Page 2: Bluetooth 4.0 and iBeacons in your iOS app - Francesco Novelli - Codemotion Milan 2014

MILAN november 28th/29th, 2014 – Francesco Novelli

Chi sono?

1. Appassionato di tecnologia!2. Freelance!3. iOS Developer4. Blogger per devApp.it5. Ex Scrittore di libri6. Ex Web Developer

Page 3: Bluetooth 4.0 and iBeacons in your iOS app - Francesco Novelli - Codemotion Milan 2014

MILAN november 28th/29th, 2014 – Francesco Novelli

Thanks to:

blinkar

http://blinkar.it

Page 4: Bluetooth 4.0 and iBeacons in your iOS app - Francesco Novelli - Codemotion Milan 2014

MILAN november 28th/29th, 2014 – Francesco Novelli

Agenda:

• Bluetooth 4.0• iBeacons• Beacons alternatives• iOS 7…7.1….8!

Page 5: Bluetooth 4.0 and iBeacons in your iOS app - Francesco Novelli - Codemotion Milan 2014

MILAN november 28th/29th, 2014 – Francesco Novelli

Bluetooth 4.0: cos’è?

• BLE: Bluetooth Low Energy

• Standard, niente draft! (dal 2010)

• Chip diverso da 3.0 e non retro compatibile

• Dual Chip Device

Page 6: Bluetooth 4.0 and iBeacons in your iOS app - Francesco Novelli - Codemotion Milan 2014

MILAN november 28th/29th, 2014 – Francesco Novelli

LOW ENERGY!!!!

Page 7: Bluetooth 4.0 and iBeacons in your iOS app - Francesco Novelli - Codemotion Milan 2014

MILAN november 28th/29th, 2014 – Francesco Novelli

Bluetooth 4.0: Le novità “minori”

• Niente abbinamenti, accoppiamenti, PIN, attese• Advertising continuo (se acceso…)• Low energy

MIN 0.01 - MAX 0.5 Old Bluetooth 1

• Meno Range (50m vs 100m)• Meno Throughput (0.27Mbit/s vs 2.1 Mbit/s)• Meno Latency (6ms vs 100ms)

Page 8: Bluetooth 4.0 and iBeacons in your iOS app - Francesco Novelli - Codemotion Milan 2014

MILAN november 28th/29th, 2014 – Francesco Novelli

Bluetooth 4.0: A cosa non serve

• Auricolari• Scambio dati• Cuffie• …• e quindi??

Page 9: Bluetooth 4.0 and iBeacons in your iOS app - Francesco Novelli - Codemotion Milan 2014

MILAN november 28th/29th, 2014 – Francesco Novelli

Bluetooth 4.0: A cosa serve

• IoT Internet of Things• Orologi (Apple Watch, Android Wear, Pebble)• Sport e device fitness• Healtcare• Security• Proxymity• Automation• Everything!

Page 10: Bluetooth 4.0 and iBeacons in your iOS app - Francesco Novelli - Codemotion Milan 2014

MILAN november 28th/29th, 2014 – Francesco Novelli

Bluetooth 4.0: Profili di utilizzo

• GATT: is.gd/blegatt• Da leggere per

developer• Da leggere per ogni

hardware makers• Adattare il device BLE

con i profili

Page 11: Bluetooth 4.0 and iBeacons in your iOS app - Francesco Novelli - Codemotion Milan 2014

MILAN november 28th/29th, 2014 – Francesco Novelli

Bluetooth 4.0 e iOS

• CoreBluetooth• iOS e Mac OS X• Bluetooth ad alto livello

Page 12: Bluetooth 4.0 and iBeacons in your iOS app - Francesco Novelli - Codemotion Milan 2014

MILAN november 28th/29th, 2014 – Francesco Novelli

Bluetooth 4.0 e iOS

• CBCentralManager: • CBPeripheral: device bluetooth• CBService: servizi del device• CBCharacteristic: informazioni del servizio

Page 13: Bluetooth 4.0 and iBeacons in your iOS app - Francesco Novelli - Codemotion Milan 2014

MILAN november 28th/29th, 2014 – Francesco Novelli

Bluetooth 4.0 e iOS

123

Page 14: Bluetooth 4.0 and iBeacons in your iOS app - Francesco Novelli - Codemotion Milan 2014

MILAN november 28th/29th, 2014 – Francesco Novelli

DEMO

Page 15: Bluetooth 4.0 and iBeacons in your iOS app - Francesco Novelli - Codemotion Milan 2014

MILAN november 28th/29th, 2014 – Francesco Novelli

Bluetooth 4.0 e iOS

• iPhone 4s +• Mac

Thanks to theapplelounge.com

Page 16: Bluetooth 4.0 and iBeacons in your iOS app - Francesco Novelli - Codemotion Milan 2014

MILAN november 28th/29th, 2014 – Francesco Novelli

iBeacon

• Cos’è?• Come funziona?• Dove si trova?• Quanto costa?• Come lo uso?

Page 17: Bluetooth 4.0 and iBeacons in your iOS app - Francesco Novelli - Codemotion Milan 2014

MILAN november 28th/29th, 2014 – Francesco Novelli

iBeacon

iBeacon, a new class of low-powered, low-cost transmitters that can notify nearby iOS 7 devices of their presence, provides apps a whole new level of location awareness, such as trail markers in a park, exhibits in a museum, or product displays in stores.

Page 18: Bluetooth 4.0 and iBeacons in your iOS app - Francesco Novelli - Codemotion Milan 2014

MILAN november 28th/29th, 2014 – Francesco Novelli

iBeacon: notify…what?

• UDID (Hex ID)• Major (Int)• Minor (Int)• …• Sempre!• A chiunque, in broadcasting

Page 19: Bluetooth 4.0 and iBeacons in your iOS app - Francesco Novelli - Codemotion Milan 2014

MILAN november 28th/29th, 2014 – Francesco Novelli

iBeacon: Sample

• UUDID: E2C56DB5-DFFB-48D2-B060-D0F5A71096E0 Museo Uffizi

• Major: int 2 Piano 2

• Minor: int 13 Quadro 13

• quindi…

• sei nel Museo al secondo piano davanti al quadro 13.propongo audio guida per quel quadro.

Page 20: Bluetooth 4.0 and iBeacons in your iOS app - Francesco Novelli - Codemotion Milan 2014

MILAN november 28th/29th, 2014 – Francesco Novelli

iBeacon: cos’è fisicamente?

Page 21: Bluetooth 4.0 and iBeacons in your iOS app - Francesco Novelli - Codemotion Milan 2014

MILAN november 28th/29th, 2014 – Francesco Novelli

iBeacon da iDevice• CoreBluetooth.framework

(AirLocate sample code)

_peripheralManager = [[CBPeripheralManager alloc] initWithDelegate:self queue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)];

NSDictionary *peripheralData = nil;if(_uuid && _major && _minor){CLBeaconRegion *region = [[CLBeaconRegion alloc] initWithProximityUUID:_uuid

major:[_major shortValue] minor:[_minor shortValue]

identifier:@"com.apple.AirLocate"];peripheralData = [region peripheralDataWithMeasuredPower:_power];}

[_peripheralManager startAdvertising:peripheralData];

Page 22: Bluetooth 4.0 and iBeacons in your iOS app - Francesco Novelli - Codemotion Milan 2014

MILAN november 28th/29th, 2014 – Francesco Novelli

iBeacon: Gli altri

Page 23: Bluetooth 4.0 and iBeacons in your iOS app - Francesco Novelli - Codemotion Milan 2014

MILAN november 28th/29th, 2014 – Francesco Novelli

iBeacon: Estimote

• Largamente apprezzati• Versione stickers (accelerometro e

temperatura)• Custom SDK• Android SDK• Costo elevato

Page 24: Bluetooth 4.0 and iBeacons in your iOS app - Francesco Novelli - Codemotion Milan 2014

MILAN november 28th/29th, 2014 – Francesco Novelli

iBeacon: Gimbal

• Qualcomm!• Prezzo basso• Programmabili via iPhone• SDK potenziato (non obbligatorio)• Controllo via web (con SDK proprietario)• Android SDK• Consumo batteria da rivedere• Versione Tag o Device

Page 25: Bluetooth 4.0 and iBeacons in your iOS app - Francesco Novelli - Codemotion Milan 2014

MILAN november 28th/29th, 2014 – Francesco Novelli

iBeacon: Consumi

http://is.gd/ibeaconcomp

Page 26: Bluetooth 4.0 and iBeacons in your iOS app - Francesco Novelli - Codemotion Milan 2014

MILAN november 28th/29th, 2014 – Francesco Novelli

iBeacon: Come lo uso?

NOTIFY MONITORING

Page 27: Bluetooth 4.0 and iBeacons in your iOS app - Francesco Novelli - Codemotion Milan 2014

MILAN november 28th/29th, 2014 – Francesco Novelli

Page 28: Bluetooth 4.0 and iBeacons in your iOS app - Francesco Novelli - Codemotion Milan 2014

MILAN november 28th/29th, 2014 – Francesco Novelli

iBeacon: Notify

• CLLocationManager e delegate• Metodo delegate chiamato ad ogni entrata o

uscita da una CLBeaconRegion (campo iBeacon)

• Disponibile anche ad app in background• Si può osservare un UUID o una iBeacon

(UUID + Major + Minor)

Page 29: Bluetooth 4.0 and iBeacons in your iOS app - Francesco Novelli - Codemotion Milan 2014

MILAN november 28th/29th, 2014 – Francesco Novelli

iBeacon: Notify

_locationManager = [[CLLocationManager alloc] init];_locationManager.delegate = self; CLBeaconRegion *region = nil;_uuid = [[NSUUID alloc] initWithUUIDString:@“E2C56DB5-DFFB-48D2-B060-D0F5A71096E0"];region = [[CLBeaconRegion alloc] initWithProximityUUID:_uuid

identifier:@"com.apple.AirLocate"];region.notifyOnEntry = YES;region.notifyOnExit = YES;region.notifyEntryStateOnDisplay = YES; [_locationManager startMonitoringForRegion:region];

Page 30: Bluetooth 4.0 and iBeacons in your iOS app - Francesco Novelli - Codemotion Milan 2014

MILAN november 28th/29th, 2014 – Francesco Novelli

iBeacon: Notify delegate

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

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

- (void)locationManager:(CLLocationManager *)manager      didDetermineState:(CLRegionState)state              forRegion:(CLRegion *)region;

Page 31: Bluetooth 4.0 and iBeacons in your iOS app - Francesco Novelli - Codemotion Milan 2014

MILAN november 28th/29th, 2014 – Francesco Novelli

iBeacon: Notify, quando?

• Location awareness push notification• Interattività dell’app• Pagamenti

Page 32: Bluetooth 4.0 and iBeacons in your iOS app - Francesco Novelli - Codemotion Milan 2014

MILAN november 28th/29th, 2014 – Francesco Novelli

iBeacon: Monitoring

• CLLocationManager e delegate• Metodo del delegate invocato ogni secondo

(se ci sono 1 o più beacon)• Array di beacons

Page 33: Bluetooth 4.0 and iBeacons in your iOS app - Francesco Novelli - Codemotion Milan 2014

MILAN november 28th/29th, 2014 – Francesco Novelli

iBeacon: Monitoring

_locationManager = [[CLLocationManager alloc] init];_locationManager.delegate = self; CLBeaconRegion *region = nil;_uuid = [[NSUUID alloc] initWithUUIDString:@“E2C56DB5-DFFB-48D2-B060-D0F5A71096E0"];region = [[CLBeaconRegion alloc] initWithProximityUUID:_uuid

identifier:@"com.apple.AirLocate"];[_locationManager startRangingBeaconsInRegion:region];

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

NSLog(@"Major: %@, Minor: %@, Acc: %.2fm %li", beacon.major, beacon.minor, beacon.accuracy, beacon.proximity);

}

Page 34: Bluetooth 4.0 and iBeacons in your iOS app - Francesco Novelli - Codemotion Milan 2014

MILAN november 28th/29th, 2014 – Francesco Novelli

iBeacon: Monitoring, quando?

• Geofencing al chiuso• Elencare beacons vicini• Ottenere le distanza da un beacon• Visualizzare informazioni con app aperta

Page 35: Bluetooth 4.0 and iBeacons in your iOS app - Francesco Novelli - Codemotion Milan 2014

MILAN november 28th/29th, 2014 – Francesco Novelli

iBeacon: iOS Roadmap

• 7.0 Introduzione• 7.1 Notify con app killate

Velocità maggiore per le notifiche• 8.0 Continuity Icon

Page 36: Bluetooth 4.0 and iBeacons in your iOS app - Francesco Novelli - Codemotion Milan 2014

MILAN november 28th/29th, 2014 – Francesco Novelli

iBeacon: Case history

• MLB• Virgin• Apple Store• Musei Palazzo Farnese• Nazioni unite• Parchi floreali• Caccia al tesoro• …

Page 37: Bluetooth 4.0 and iBeacons in your iOS app - Francesco Novelli - Codemotion Milan 2014

MILAN november 28th/29th, 2014 – Francesco Novelli

iBeacon: Android

• Android 4.3+ (e.g. Samsung Galaxy S3/S4/S4 Mini, Samsung Galaxy Note 2/3, HTC One, Google/LG Nexus 7 2013 version/Nexus 4/Nexus 5, HTC Butterfly, OnePlus One)

• SDK produttori (Gimbal, Estimote, etc)• AltBeacon Project

Page 38: Bluetooth 4.0 and iBeacons in your iOS app - Francesco Novelli - Codemotion Milan 2014

MILAN november 28th/29th, 2014 – Francesco Novelli

iBeacon: Resources

• iBeacon Bible• developer.apple.com/ibeacon• WWDC 2014 Session 307 – What’s New In

Core Location• AirLocate Sample Code

Page 39: Bluetooth 4.0 and iBeacons in your iOS app - Francesco Novelli - Codemotion Milan 2014

MILAN november 28th/29th, 2014

Bluetooth 4.0 and iBeacons in your iOS [email protected] - [email protected]

ThanksFrancesco Novelli