practical core bluetooth in iot & wearable projects @ altconf 2016

259
Practical Core Bluetooth in IoT & Wearable projects Shuichi Tsutsumi @shu223 AltConf 2016 - San Francisco

Upload: shuichi-tsutsumi

Post on 05-Apr-2017

1.222 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Practical Core Bluetooth

in IoT & Wearable projects

Shuichi Tsutsumi @shu223 AltConf 2016 - San Francisco

Page 2: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016
Page 3: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016
Page 4: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016
Page 5: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

iOS-10-Sampler

https://github.com/shu223

Page 7: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Overview

•Basics of Core Bluetooth

•Practical Core Bluetooth

Based on my experience!

Page 8: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Bluetooth Low Energy?

Page 9: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Bluetooth Low Energy (BLE)

Page 10: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Bluetooth Low Energy (BLE)• Wireless technology

Page 11: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Bluetooth Low Energy (BLE)• Wireless technology

- no network infrastructure required

Page 12: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Bluetooth Low Energy (BLE)• Wireless technology

- no network infrastructure required

Wi-Fi

Page 13: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Bluetooth Low Energy (BLE)• Wireless technology

- no network infrastructure required

BLE

Page 14: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

• Low energy

Page 15: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

• Low energy

• NOT compatible with Classic BT

Page 16: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

• Low energy

• NOT compatible with Classic BT

• Uses 2.4 GHz radio frequencies

Page 17: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

• Low energy

• NOT compatible with Classic BT

• Uses 2.4 GHz radio frequencies

• Marketed by the Bluetooth SIG

Page 18: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

• Low energy

• NOT compatible with Classic BT

• Uses 2.4 GHz radio frequencies

• Marketed by the Bluetooth SIG

• etc…

Page 19: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

• Low energy

• NOT compatible with Classic BT

• Uses 2.4 GHz radio frequencies

• Marketed by the Bluetooth SIG

• etc…

Page 20: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

The most important thing for

iOS developers

Page 21: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

The API ‘Core Bluetooth’ is open for developers

Page 22: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

The API ‘Core Bluetooth’ is open for developers

• API for Classic BT is NOT open.

- Requires MFi certification.

Page 23: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

BLE is almost the ONLY way to enable iOS apps to communicate with external hardware without infrastructure or MFi.

Page 24: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Basics of Core Bluetooth

Page 26: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Moff Band Moff App

Page 27: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Moff Band Moff App

BLE Connection

Page 28: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Moff Band Moff App

BLE Connection

Sensors - Gyroscope - Accelerometer

Page 29: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Moff Band Moff App

Sensor Data

BLE Connection

Sensors - Gyroscope - Accelerometer

Page 30: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Moff Band Moff App

Sensor Data

BLE Connection

Sensors - Gyroscope - Accelerometer

Analyze sensor data

Page 31: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Moff Band Moff App

Sensor Data

BLE Connection

Sensors - Gyroscope - Accelerometer

Analyze sensor data

Recognize - Gesture - Posture

Page 32: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Moff Band Moff App

Sensor Data

BLE Connection

Sensors - Gyroscope - Accelerometer

Analyze sensor data

Recognize - Gesture - Posture

Play sounds

Page 33: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Sensor Data

BLE Connection

How is sensor data sent with Core Bluetooth?

Page 34: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Step 1. Scan

Page 35: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Step 1. Scan: Search for nearby BLE devices

Page 36: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Step 1. Scan: Search for nearby BLE devices

Page 37: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Step 1. Scan

Advertise

: Search for nearby BLE devices

Page 38: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Scan

Step 1. Scan

Advertise

: Search for nearby BLE devices

Page 39: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Scan

Step 1. Scan

Advertise

: Search for nearby BLE devices

centralManager.scanForPeripheralsWithServices(nil, options: nil)

Page 40: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Scan

Step 1. Scan

Advertise

Discover

: Search for nearby BLE devices

Page 41: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Scan

Step 1. Scan

Advertise

Discover

: Search for nearby BLE devices

func centralManager(central: CBCentralManager, didDiscoverPeripheral peripheral: CBPeripheral, advertisementData: [String : AnyObject], RSSI: NSNumber!) { print(“Discovered a BLE device!”) }

Page 42: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Scan

Step 1. Scan

Advertise

Discover

: Search for nearby BLE devices

func centralManager(central: CBCentralManager, didDiscoverPeripheral peripheral: CBPeripheral, advertisementData: [String : AnyObject], RSSI: NSNumber!) { print(“Discovered a BLE device!”) }

Central

Page 43: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Scan

Step 1. Scan

Advertise

Discover

: Search for nearby BLE devices

func centralManager(central: CBCentralManager, didDiscoverPeripheral peripheral: CBPeripheral, advertisementData: [String : AnyObject], RSSI: NSNumber!) { print(“Discovered a BLE device!”) }

Peripheral Central

Page 44: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Step 2. Connect

Page 45: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Connect

Step 2. Connect

Page 46: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Connect

Step 2. Connect

centralManager.connectPeripheral(peripheral, options: nil)

Page 47: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Connect

Step 2. Connect

centralManager.connectPeripheral(peripheral, options: nil)

func centralManager(central: CBCentralManager, didConnectPeripheral peripheral: CBPeripheral) { print(“Connected!”) }

Page 48: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Step 3. Subscribe

Page 49: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Step 3. Subscribe : Ready to receive data

Page 50: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Step 3. Subscribe : Ready to receive data

GATT = Generic Attribute Profile

Page 51: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Moff Service

xx Service

Step 3. Subscribe : Ready to receive data

GATT = Generic Attribute Profile

Page 52: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Moff Service

xx Service

Button Characteristic

xx Characteristic

Sensor Characteristic

Step 3. Subscribe : Ready to receive data

GATT = Generic Attribute Profile

Page 53: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Moff Service

xx Service

Button Characteristic

xx Characteristic

Sensor Characteristic

Subscribe (Request to be notified)

Step 3. Subscribe : Ready to receive data

GATT = Generic Attribute Profile

Page 54: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Moff Service

xx Service

Button Characteristic

xx Characteristic

Sensor Characteristic

Subscribe (Request to be notified)

Step 3. Subscribe : Ready to receive data

GATT = Generic Attribute Profile

peripheral.setNotifyValue(true, forCharacteristic: c)

Page 55: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Step 4. Notify

Moff Service

Sensor Characteristic

xxxx Characteristic

Page 56: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Step 4. Notify

Moff Service

Sensor Characteristic

xxxx Characteristic

Update the value

Page 57: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Step 4. Notify

Notify subscribers

Moff Service

Sensor Characteristic

xxxx Characteristic

Update the value

Page 58: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Step 4. Notify

Notify subscribers

Moff Service

Sensor Characteristic

xxxx Characteristic

Update the value

func peripheral(peripheral: CBPeripheral, didUpdateValueForCharacteristic characteristic: CBCharacteristic, error: NSError?) { print(“Received sensor data!”) }

Page 59: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Step 4. Notify

Notify subscribers

Moff Service

Sensor Characteristic

xxxx Characteristic

Update the value

func peripheral(peripheral: CBPeripheral, didUpdateValueForCharacteristic characteristic: CBCharacteristic, error: NSError?) { print(“Received sensor data!”) }

Page 60: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Hardware Side?

Page 61: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Hardware Side?I’m sorry, I don’t know…

Page 62: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

BLE

Page 63: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

BLE

iOS Engineer

Page 64: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

BLE

iOS Engineer

Page 65: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

BLE

Firmware Engineer iOS Engineer

Page 66: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

BLE

Firmware Engineer iOS Engineer

Page 67: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Hardware Projects I’ve worked on

as an iOS engineer

Page 68: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Wheelchair ‘WHILL’

Page 69: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Wheelchair ‘WHILL’

Page 70: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Wearable Walkie-Talkie ‘BONX’

Page 71: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Wearable Walkie-Talkie ‘BONX’

Page 72: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Wearable Walkie-Talkie ‘BONX’

Page 73: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016
Page 74: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Group conversation system with VoIP

Page 75: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Group conversation system with VoIP

- Detects the human voice

Page 76: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Group conversation system with VoIP

- Detects the human voice

- Cuts out all background noise

Page 77: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Group conversation system with VoIP

- Detects the human voice

- Cuts out all background noise

→ Can be used even in areas with poor coverage!

Page 78: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

BLE for BONX

Page 79: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

BLE for BONX

Page 80: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

BLE for BONX

Page 81: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

BLE for BONX

Page 82: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

IoT for Cars ‘SmartDrive’

Page 84: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Music for the DeafDaito Manabe/Motoi Ishibashi/Teruoka Masaki/Shuichi Tsutsumi x SOUL FAMILY

Page 85: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Music for the DeafDaito Manabe/Motoi Ishibashi/Teruoka Masaki/Shuichi Tsutsumi x SOUL FAMILY

iPhone

Page 86: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Music for the DeafDaito Manabe/Motoi Ishibashi/Teruoka Masaki/Shuichi Tsutsumi x SOUL FAMILY

Electronic Stimulation DeviceiPhone

Page 87: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Music for the DeafDaito Manabe/Motoi Ishibashi/Teruoka Masaki/Shuichi Tsutsumi x SOUL FAMILY

Commands

Electronic Stimulation DeviceiPhone

Page 88: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Music for the DeafDaito Manabe/Motoi Ishibashi/Teruoka Masaki/Shuichi Tsutsumi x SOUL FAMILY

Page 89: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Practical Core Bluetooth

Page 90: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Defining GATT

Page 91: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

GATT to send sensor data

Foo Service

Sensor Data Characteristic

UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Bar Service

xx Characteristic

UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Properties: Notify

Value: acc x, acc y, acc z, gyro x, gyro y, gyro z (2bytes for each)

xx Characteristic

Page 92: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

GATT to send sensor data

Foo Service

Sensor Data Characteristic

UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Bar Service

xx Characteristic

UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Properties: Notify

Value: acc x, acc y, acc z, gyro x, gyro y, gyro z (2bytes for each)

xx Characteristic

Page 93: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

GATT to send sensor data

Foo Service

Sensor Data Characteristic

UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Bar Service

xx Characteristic

UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Properties: Notify

Value: acc x, acc y, acc z, gyro x, gyro y, gyro z (2bytes for each)

xx Characteristic

Page 94: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

GATT to send sensor data

Foo Service

Sensor Data Characteristic

UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Bar Service

xx Characteristic

UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Properties: Notify

Value: acc x, acc y, acc z, gyro x, gyro y, gyro z (2bytes for each)

xx Characteristic

Page 95: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

GATT to send sensor data

Foo Service

Sensor Data Characteristic

UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Bar Service

xx Characteristic

UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Properties: Notify

Value: acc x, acc y, acc z, gyro x, gyro y, gyro z (2bytes for each)

xx Characteristic

Page 96: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

GATT to send sensor data

Foo Service

Sensor Data Characteristic

UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Bar Service

xx Characteristic

UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Properties: Notify

Value: acc x, acc y, acc z, gyro x, gyro y, gyro z (2bytes for each)

xx Characteristic

Page 97: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

GATT to send button interactions

Foo Service

Button Control Characteristic

UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Properties: Notify

Value: 0x01 or 0x00

Page 98: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

GATT to send button interactions

Foo Service

Button Control Characteristic

UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Properties: Notify

Value: 0x01 or 0x00

Page 99: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

GATT to send button interactions

Foo Service

Button Control Characteristic

UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Properties: Notify

Value: 0x01 or 0x00

Page 100: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

GATT to send button interactions

Foo Service

Button Control Characteristic

UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Properties: Notify

Value: 0x01 or 0x00

Button interactions

Page 101: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

GATT to send button interactions

Foo Service

Button Control Characteristic

UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Properties: Notify

Value: 0x01 or 0x00

Button interactions

Page 102: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

GATT to send button interactions

Foo Service

Button Control Characteristic

UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Properties: Notify

Value: 0x01 or 0x00

Button interactions

Page 103: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

GATT to send button interactions

Foo Service

Button Control Characteristic

UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Properties: Notify

Value: 0x01 or 0x00

Button interactions

0x01: Pushed 0x00: Released

Page 104: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

GATT for remote control

Foo Service

Remote Control Characteristic

UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Properties: Write

Value: Horizontal (-100 ~ 100), Vertical (-100 ~ 100)

Page 105: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

GATT for remote control

Foo Service

Remote Control Characteristic

UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Properties: Write

Value: Horizontal (-100 ~ 100), Vertical (-100 ~ 100)

Page 106: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

GATT for remote control

Foo Service

Remote Control Characteristic

UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Properties: Write

Value: Horizontal (-100 ~ 100), Vertical (-100 ~ 100)

values

Page 107: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

GATT for remote control

Foo Service

Remote Control Characteristic

UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Properties: Write

Value: Horizontal (-100 ~ 100), Vertical (-100 ~ 100)

values

Page 108: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

GATT for remote control

Foo Service

Remote Control Characteristic

UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Properties: Write

Value: Horizontal (-100 ~ 100), Vertical (-100 ~ 100)

values

Page 109: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

GATT for generic commands

Page 110: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

GATT for generic commands

Electronic Stimulation Control Characteristic

UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Properties: Write

Value: 1 byte

Page 111: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

GATT for generic commands

Electronic Stimulation Control Characteristic

UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Properties: Write

Value: 1 byte

Page 112: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

GATT for generic commands

Electronic Stimulation Control Characteristic

UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Properties: Write

Value: 1 byte

4 Commands: - Change the pulse frequency - Change the electric current - Right channels on/off - Left channels on/off

Page 113: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

GATT for generic commands

Electronic Stimulation Control Characteristic

UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Properties: Write

Value: 1 byte

4 Commands: - Change the pulse frequency - Change the electric current - Right channels on/off - Left channels on/off

Page 114: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

GATT for generic commands

Electronic Stimulation Control Characteristic

UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Properties: Write

Value: 1 byte

High-order 2 bits - 00: Change the pulse frequency - 01: Change the electric current - 10: Left channels on/off - 11: Right channels on/off

Page 115: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

GATT for generic commands

Electronic Stimulation Control Characteristic

UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Properties: Write

Value: 1 byte

High-order 2 bits - 00: Change the pulse frequency - 01: Change the electric current - 10: Left channels on/off - 11: Right channels on/off

Page 116: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

How to define GATT

Page 117: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

How to define GATT1. Create UUID for the service & characteristic

Page 118: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

How to define GATT1. Create UUID for the service & characteristic

$ uuidgen CEEA31BC-BEAC-4A78-B7ED-FC96B6254D4C

Page 119: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

How to define GATT1. Create UUID for the service & characteristic

2. Define the properties (Read, Notify, Write, etc.)

$ uuidgen CEEA31BC-BEAC-4A78-B7ED-FC96B6254D4C

Page 120: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

How to define GATT1. Create UUID for the service & characteristic

2. Define the properties (Read, Notify, Write, etc.)

Peripheral → Central: Notify Central → Peripheral: Write

$ uuidgen CEEA31BC-BEAC-4A78-B7ED-FC96B6254D4C

Page 121: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

How to define GATT1. Create UUID for the service & characteristic

2. Define the properties (Read, Notify, Write, etc.)

Peripheral → Central: Notify Central → Peripheral: Write

3. Define the value format

$ uuidgen CEEA31BC-BEAC-4A78-B7ED-FC96B6254D4C

Page 122: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

How to define GATT1. Create UUID for the service & characteristic

2. Define the properties (Read, Notify, Write, etc.)

Peripheral → Central: Notify Central → Peripheral: Write

3. Define the value format

Usually limited to 20 bytes

$ uuidgen CEEA31BC-BEAC-4A78-B7ED-FC96B6254D4C

Page 123: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Reference: GATT profiles by Bluetooth SIG

Page 124: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Defining background behaviors

Page 125: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Background behaviors on iOS• Very limited

- Listening to music

- Getting location data

- Downloading data

Page 126: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Imagine

Page 127: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

If BLE didn’t work in the background…

Page 128: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016
Page 129: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

You would have to always keep the app in the foreground, while snowboarding!

Page 130: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016
Page 131: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

You would have to launch the app whenever you go driving!

Page 132: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

What functions can be used in the background?

Page 133: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

What functions can be used in the background?

• Scanning peripherals

Page 134: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

What functions can be used in the background?

• Scanning peripherals

• Connecting with peripherals

Page 135: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

What functions can be used in the background?

• Scanning peripherals

• Connecting with peripherals

• Reading characteristics’ value

Page 136: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

What functions can be used in the background?

• Scanning peripherals

• Connecting with peripherals

• Reading characteristics’ value

• Writing characteristics’ value

Page 137: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

What functions can be used in the background?

• Scanning peripherals

• Connecting with peripherals

• Reading characteristics’ value

• Writing characteristics’ value

• Receiving notifications

Page 138: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

What functions can be used in the background?

• Scanning peripherals

• Connecting with peripherals

• Reading characteristics’ value

• Writing characteristics’ value

• Receiving notifications

Almost all functions can be used even in the background!

Page 139: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

How to support background mode

Page 140: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016
Page 141: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Just check this box!

Page 142: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Limitations

Page 143: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Limitations• Longer intervals for scanning

Page 144: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Limitations• Longer intervals for scanning

• Must explicitly specify one or more services to scan

Page 145: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Limitations• Longer intervals for scanning

• Must explicitly specify one or more services to scan

• CBCentralManagerOptionShowPowerAlertKey option is ignored

Page 146: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Limitations• Longer intervals for scanning

• Must explicitly specify one or more services to scan

• CBCentralManagerOptionShowPowerAlertKey option is ignored

Resources

- Core Bluetooth Programming Guide

- Core Bluetooth Framework Reference (also in headers)

Page 147: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

If the app in the background is killed by the system…

Page 148: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016
Page 149: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

State Preservation and Restoration

Page 150: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

State Preservation and Restoration

The system takes over the BLE tasks even after the app is killed.

Page 151: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

State Preservation and Restoration

The system takes over the BLE tasks even after the app is killed.

- Preserves the state of the app’s central managers and continues the BLE tasks on their behalf.

Page 152: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

State Preservation and Restoration

The system takes over the BLE tasks even after the app is killed.

- Preserves the state of the app’s central managers and continues the BLE tasks on their behalf.

- Relaunches the app into the background and calls the corresponding delegate method.

Page 153: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

State Preservation and Restoration

The system takes over the BLE tasks even after the app is killed.

- Preserves the state of the app’s central managers and continues the BLE tasks on their behalf.

- Relaunches the app into the background and calls the corresponding delegate method.

→ The app can handle BLE events!

Page 154: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016
Page 155: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

• The app is killed by the system

Page 156: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

• The app is killed by the system

• The user pushes the button on the peripheral device

Page 157: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

• The app is killed by the system

• The user pushes the button on the peripheral device

• The system receives the notification

Page 158: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

• The app is killed by the system

• The user pushes the button on the peripheral device

• The system receives the notification

• The app is relaunched in the BG and the delegate method is called.

Page 159: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

func peripheral(peripheral: CBPeripheral, didUpdateValueForCharacteristic characteristic: CBCharacteristic, error: NSError?) { print(“Received the characteristic data!”) }

• The app is killed by the system

• The user pushes the button on the peripheral device

• The system receives the notification

• The app is relaunched in the BG and the delegate method is called.

Page 160: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

func peripheral(peripheral: CBPeripheral, didUpdateValueForCharacteristic characteristic: CBCharacteristic, error: NSError?) { print(“Received the characteristic data!”) }

• The app is killed by the system

• The user pushes the button on the peripheral device

• The system receives the notification

• The app is relaunched in the BG and the delegate method is called.

The app can process the button interaction!

Page 161: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Implementation

Page 162: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Implementation• Add an option when initializing the

CBCentralManager object.

let options = [ CBCentralManagerOptionRestoreIdentifierKey: "somekey" ] centralManager = CBCentralManager( delegate: self, queue: queue, options: options)

Page 163: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Implementation• Implement the delegate method which is called when

the app is restored.

func centralManager(central: CBCentralManager, willRestoreState dict: [String : AnyObject]) { print("Restored") }

Page 164: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Testing the restoration

Page 165: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Testing the restoration• Kill the app as if it was killed by the iOS

kill(getpid(), SIGKILL);

Page 166: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

How to test without HW prototypes

Page 167: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Did the HW prototypes exist when develop the apps?

Projects HW prototypes existed?

Moff YES

WHILL NOBONX NOSmartDrive YES

PLEN2 NOMusic for the Deaf NO

Page 168: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Development Kit

Page 169: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Development KitBLE Module

Page 170: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Development KitBLE Module

Display

Page 171: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Development KitBLE Module

Display

USB interface

Page 172: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Development KitBLE Module

Display

USB interface

Battery box

Page 173: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Development Kit

Can start development without creating a circuit ourselves

BLE ModuleDisplay

USB interface

Battery box

Page 174: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016
Page 175: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Development Kit

Page 176: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Development Kit App

Page 177: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Development Kit AppBLE

Page 178: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Horizontal (-100~100) / Vertical (-100~100)

Development Kit AppBLE

Page 179: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016
Page 180: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Emulator App

Page 181: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Emulator App

• Develop another iOS app as the alternative to the peripheral device

Page 182: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Emulator App

• Develop another iOS app as the alternative to the peripheral device

• Use CBPeripheralManager

Page 183: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Emulator App

• Develop another iOS app as the alternative to the peripheral device

• Use CBPeripheralManager

• Easier for iOS engineers

Page 184: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016
Page 185: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016
Page 186: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016
Page 187: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

=

Page 188: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Multi-Function Control • Single Tap • Double Tap • Long Press • Very Long Press

=

Page 189: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Troubleshooting

Page 190: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Can’t find the peripheral

Scan

?

Page 191: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Can’t connect

Find

Page 192: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Can’t connect

Connect

×

Page 193: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

• Connection dropped

Page 194: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

• Connection dropped

• Can’t discover services or characteristics

Page 195: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

• Connection dropped

• Can’t discover services or characteristics• Fail to write

Page 196: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

• Connection dropped

• Can’t discover services or characteristics• Fail to write• Incorrect characteristic values

Page 197: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

• Connection dropped

• Can’t discover services or characteristics• Fail to write• Incorrect characteristic values

• Incorrect behaviors in the background

Page 198: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

• Connection dropped

• Can’t discover services or characteristics• Fail to write• Incorrect characteristic values

• Incorrect behaviors in the background• etc…

Page 199: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Identify which side the problem is on

Is the problem on the central side or on the peripheral side?

→ Compare with another iOS app like ‘LightBlue’

Page 200: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Can’t find the peripheral

• Scanning, but can’t find the peripheral device

Page 201: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Can’t find the peripheral

• Scanning, but can’t find the peripheral device

Scan

Page 202: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Can’t find the peripheral

• Scanning, but can’t find the peripheral device

Scan

but ‘didDiscover’ method isn’t called

Page 203: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Can’t find the peripheral• Scan with another iOS app

Scan

Page 204: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Can’t find the peripheral• Scan with another iOS app

Scan

Discovered peripherals

Page 205: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Can’t connect, etc.

Connect

Page 206: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Can’t connect, etc.

Connect

Services & Characteristics

Page 207: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Other debugging tools

Page 208: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Bluetooth ExplorermacOS app made by Apple

Page 209: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016
Page 210: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Low Energy Devices

Page 211: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Low Energy DevicesScan, Connect

Page 212: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Low Energy DevicesScan, Connect

Details of services and characteristics

Page 213: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Low Energy DevicesScan, Connect

Details of services and characteristics

Write, Read, Subscribe

Page 214: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

func centralManager( central: CBCentralManager, didDiscoverPeripheral peripheral: CBPeripheral, advertisementData: [String : AnyObject], RSSI: NSNumber!) { print(advertisementData) }

Page 215: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

func centralManager( central: CBCentralManager, didDiscoverPeripheral peripheral: CBPeripheral, advertisementData: [String : AnyObject], RSSI: NSNumber!) { print(advertisementData) }

Filtered by iOS!

Page 216: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

func centralManager( central: CBCentralManager, didDiscoverPeripheral peripheral: CBPeripheral, advertisementData: [String : AnyObject], RSSI: NSNumber!) { print(advertisementData) }

Filtered by iOS!→ Can’t see all of the advertisement data

Page 217: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

func centralManager( central: CBCentralManager, didDiscoverPeripheral peripheral: CBPeripheral, advertisementData: [String : AnyObject], RSSI: NSNumber!) { print(advertisementData) }

Filtered by iOS!→ Can’t see all of the advertisement data

e.g. Can’t see the ‘Manufacture Data’ field of iBeacon

Page 218: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016
Page 219: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Not filtered →Can see the ‘Manufacture Data’ field of iBeacon

Page 220: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Packet Logger

macOS app made by Apple

Page 221: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016
Page 222: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016
Page 223: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

How to get

Page 224: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

How to get

Download ‘Hardware IO Tools for Xcode’

Page 225: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

How to get

Download ‘Hardware IO Tools for Xcode’

Page 226: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

How to get

Download ‘Hardware IO Tools for Xcode’

Page 227: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

How to get

Download ‘Hardware IO Tools for Xcode’

Page 228: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

App Review

Page 229: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016
Page 230: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

MSRP $13,995

Page 231: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Costing too much

Page 232: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Not enough devices when submitting

Page 233: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Videos for review

Page 234: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Videos for review

• Show how the app works with the peripheral device

Page 235: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Videos for review

• Show how the app works with the peripheral device• Not need to be cool!

Page 236: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016
Page 237: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

• Shoot with iPhone

Page 238: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

• Shoot with iPhone • Edit with iMovie

Page 239: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Recap

Page 240: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Recap• What is Bluetooth Low Energy?

Page 241: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Recap• What is Bluetooth Low Energy?

• Basics of Core Bluetooth with an actual product

Page 242: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Recap• What is Bluetooth Low Energy?

• Basics of Core Bluetooth with an actual product

• Practical Core Bluetooth with specific examples

Page 243: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Recap• What is Bluetooth Low Energy?

• Basics of Core Bluetooth with an actual product

• Practical Core Bluetooth with specific examples

- Defining GATT

Page 244: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Recap• What is Bluetooth Low Energy?

• Basics of Core Bluetooth with an actual product

• Practical Core Bluetooth with specific examples

- Defining GATT

- Defining background behaviors

Page 245: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Recap• What is Bluetooth Low Energy?

• Basics of Core Bluetooth with an actual product

• Practical Core Bluetooth with specific examples

- Defining GATT

- Defining background behaviors

- Testing without HW prototypes

Page 246: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Recap• What is Bluetooth Low Energy?

• Basics of Core Bluetooth with an actual product

• Practical Core Bluetooth with specific examples

- Defining GATT

- Defining background behaviors

- Testing without HW prototypes

- Troubleshooting

Page 247: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Recap• What is Bluetooth Low Energy?

• Basics of Core Bluetooth with an actual product

• Practical Core Bluetooth with specific examples

- Defining GATT

- Defining background behaviors

- Testing without HW prototypes

- Troubleshooting

- App Review

Page 248: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Core Bluetooth in iOS 10

Page 249: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Nothing special

Page 250: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016
Page 251: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016
Page 252: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

CBManager

Page 253: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016
Page 254: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

func centralManagerDidUpdateState(_ central: CBCentralManager) { print("state: \(central.state)") }

Page 255: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Initializer without arguments

Page 256: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

private var centralManager: CBCentralManager! override func viewDidLoad() { super.viewDidLoad() centralManager = CBCentralManager(delegate: self, queue: nil) }

From

Page 257: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

private let centralManager = CBCentralManager() override func viewDidLoad() { super.viewDidLoad() centralManager.delegate = self }

private var centralManager: CBCentralManager! override func viewDidLoad() { super.viewDidLoad() centralManager = CBCentralManager(delegate: self, queue: nil) }

From

To

Page 258: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016
Page 259: Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

Thank you!Shuichi Tsutsumi - iOS Freelancer

• Twitter: @shu223

• GitHub: shu223

• Blog: https://medium.com/@shu223/

• Email: [email protected]