Slide 1

Slide 1 text

Practical Core Bluetooth in IoT & Wearable projects Shuichi Tsutsumi @shu223 iOS Freelancer iOSCon 2016 - London

Slide 2

Slide 2 text

Overview • Basics of Core Bluetooth • Practical Core Bluetooth

Slide 3

Slide 3 text

Bluetooth Low Energy?

Slide 4

Slide 4 text

Bluetooth Low Energy (BLE) • Wireless technology - no network infrastructure required

Slide 5

Slide 5 text

Bluetooth Low Energy (BLE) • Wireless technology - no network infrastructure required Wi-Fi

Slide 6

Slide 6 text

Bluetooth Low Energy (BLE) • Wireless technology - no network infrastructure required BLE

Slide 7

Slide 7 text

• Low energy

Slide 8

Slide 8 text

• Low energy • NOT compatible with Classic BT

Slide 9

Slide 9 text

• Low energy • NOT compatible with Classic BT • Uses 2.4 GHz radio frequencies

Slide 10

Slide 10 text

• Low energy • NOT compatible with Classic BT • Uses 2.4 GHz radio frequencies • Marketed by the Bluetooth SIG

Slide 11

Slide 11 text

• Low energy • NOT compatible with Classic BT • Uses 2.4 GHz radio frequencies • Marketed by the Bluetooth SIG • etc…

Slide 12

Slide 12 text

• Low energy • NOT compatible with Classic BT • Uses 2.4 GHz radio frequencies • Marketed by the Bluetooth SIG • etc…

Slide 13

Slide 13 text

The most important thing for iOS developers

Slide 14

Slide 14 text

The API ‘Core Bluetooth’ is open for developers

Slide 15

Slide 15 text

The API ‘Core Bluetooth’ is open for developers • API for Classic BT is NOT open. - Requires MFi certification.

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

Basics of Core Bluetooth

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

Moff Band Moff App

Slide 20

Slide 20 text

Moff Band Moff App BLE Connection

Slide 21

Slide 21 text

Moff Band Moff App BLE Connection Sensors - Gyroscope - Accelerometer

Slide 22

Slide 22 text

Moff Band Moff App Sensor Data BLE Connection Sensors - Gyroscope - Accelerometer

Slide 23

Slide 23 text

Moff Band Moff App Sensor Data BLE Connection Sensors - Gyroscope - Accelerometer Analyze sensor data

Slide 24

Slide 24 text

Moff Band Moff App Sensor Data BLE Connection Sensors - Gyroscope - Accelerometer Analyze sensor data Recognize - Gesture - Posture

Slide 25

Slide 25 text

Moff Band Moff App Sensor Data BLE Connection Sensors - Gyroscope - Accelerometer Analyze sensor data Recognize - Gesture - Posture Play sounds

Slide 26

Slide 26 text

Sensor Data How sensor data is sent with Core Bluetooth BLE Connection

Slide 27

Slide 27 text

Step 1. Scan

Slide 28

Slide 28 text

Step 1. Scan: Search for nearby BLE devices

Slide 29

Slide 29 text

Step 1. Scan: Search for nearby BLE devices

Slide 30

Slide 30 text

Step 1. Scan Advertise : Search for nearby BLE devices

Slide 31

Slide 31 text

Scan Step 1. Scan Advertise : Search for nearby BLE devices

Slide 32

Slide 32 text

Scan Step 1. Scan Advertise : Search for nearby BLE devices centralManager.scanForPeripheralsWithServices(nil, options: nil)

Slide 33

Slide 33 text

Scan Step 1. Scan Advertise Discover : Search for nearby BLE devices

Slide 34

Slide 34 text

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!”) }

Slide 35

Slide 35 text

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

Slide 36

Slide 36 text

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

Slide 37

Slide 37 text

Step 2. Connect

Slide 38

Slide 38 text

Connect Step 2. Connect

Slide 39

Slide 39 text

Connect Step 2. Connect centralManager.connectPeripheral(peripheral, options: nil)

Slide 40

Slide 40 text

Connect Step 2. Connect centralManager.connectPeripheral(peripheral, options: nil) func centralManager(central: CBCentralManager, didConnectPeripheral peripheral: CBPeripheral) { print(“Connected!”) }

Slide 41

Slide 41 text

Step 3. Subscribe

Slide 42

Slide 42 text

Step 3. Subscribe: Ready to receive data

Slide 43

Slide 43 text

Step 3. Subscribe: Ready to receive data GATT = Generic Attribute Profile

Slide 44

Slide 44 text

Moff Service xx Service Step 3. Subscribe: Ready to receive data GATT = Generic Attribute Profile

Slide 45

Slide 45 text

Moff Service xx Service Button Characteristic xx Characteristic Sensor Characteristic Step 3. Subscribe: Ready to receive data GATT = Generic Attribute Profile

Slide 46

Slide 46 text

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

Slide 47

Slide 47 text

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)

Slide 48

Slide 48 text

Step 4. Notify Moff Service Sensor Characteristic xxxx Characteristic

Slide 49

Slide 49 text

Step 4. Notify Moff Service Sensor Characteristic xxxx Characteristic Update the value

Slide 50

Slide 50 text

Step 4. Notify Notify subscribers Moff Service Sensor Characteristic xxxx Characteristic Update the value

Slide 51

Slide 51 text

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!”) }

Slide 52

Slide 52 text

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!”) }

Slide 53

Slide 53 text

Hardware Side?

Slide 54

Slide 54 text

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

Slide 55

Slide 55 text

BLE

Slide 56

Slide 56 text

BLE iOS Engineer

Slide 57

Slide 57 text

BLE iOS Engineer

Slide 58

Slide 58 text

BLE Firmware Engineer iOS Engineer

Slide 59

Slide 59 text

BLE Firmware Engineer iOS Engineer

Slide 60

Slide 60 text

HW Projects I’ve worked on as an iOS engineer

Slide 61

Slide 61 text

Wheelchair ‘WHILL’

Slide 62

Slide 62 text

Wheelchair ‘WHILL’

Slide 63

Slide 63 text

Wearable Walkie-Talkie ‘BONX’

Slide 64

Slide 64 text

Wearable Walkie-Talkie ‘BONX’

Slide 65

Slide 65 text

Wearable Walkie-Talkie ‘BONX’

Slide 66

Slide 66 text

No content

Slide 67

Slide 67 text

Group conversation system with VoIP

Slide 68

Slide 68 text

Group conversation system with VoIP - Detects the human voice

Slide 69

Slide 69 text

Group conversation system with VoIP - Detects the human voice - Cuts out all background noise

Slide 70

Slide 70 text

→ Can be used even in areas with poor coverage! Group conversation system with VoIP - Detects the human voice - Cuts out all background noise

Slide 71

Slide 71 text

BLE for BONX

Slide 72

Slide 72 text

BLE for BONX

Slide 73

Slide 73 text

BLE for BONX

Slide 74

Slide 74 text

BLE for BONX

Slide 75

Slide 75 text

IoT for Cars ‘SmartDrive’

Slide 76

Slide 76 text

Printable Open-Source Humanoid “PLEN2”

Slide 77

Slide 77 text

Music for the Deaf %BJUP.BOBCF.PUPJ*TIJCBTIJ5FSVPLB.BTBLJ4IVJDIJ5TVUTVNJY406-'".*-:

Slide 78

Slide 78 text

Music for the Deaf %BJUP.BOBCF.PUPJ*TIJCBTIJ5FSVPLB.BTBLJ4IVJDIJ5TVUTVNJY406-'".*-: iPhone

Slide 79

Slide 79 text

Music for the Deaf %BJUP.BOBCF.PUPJ*TIJCBTIJ5FSVPLB.BTBLJ4IVJDIJ5TVUTVNJY406-'".*-: Electronic Stimulation Device iPhone

Slide 80

Slide 80 text

Music for the Deaf %BJUP.BOBCF.PUPJ*TIJCBTIJ5FSVPLB.BTBLJ4IVJDIJ5TVUTVNJY406-'".*-: Commands Electronic Stimulation Device iPhone

Slide 81

Slide 81 text

Music for the Deaf %BJUP.BOBCF.PUPJ*TIJCBTIJ5FSVPLB.BTBLJ4IVJDIJ5TVUTVNJY406-'".*-:

Slide 82

Slide 82 text

Practical Core Bluetooth

Slide 83

Slide 83 text

Defining GATT

Slide 84

Slide 84 text

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

Slide 85

Slide 85 text

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

Slide 86

Slide 86 text

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

Slide 87

Slide 87 text

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

Slide 88

Slide 88 text

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

Slide 89

Slide 89 text

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

Slide 90

Slide 90 text

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

Slide 91

Slide 91 text

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

Slide 92

Slide 92 text

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

Slide 93

Slide 93 text

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

Slide 94

Slide 94 text

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

Slide 95

Slide 95 text

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

Slide 96

Slide 96 text

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 Y1VTIFE Y3FMFBTFE

Slide 97

Slide 97 text

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)

Slide 98

Slide 98 text

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)

Slide 99

Slide 99 text

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

Slide 100

Slide 100 text

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

Slide 101

Slide 101 text

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

Slide 102

Slide 102 text

GATT for generic commands

Slide 103

Slide 103 text

GATT for generic commands Electronic Stimulation Control Characteristic UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Properties: Write Value: 1 byte

Slide 104

Slide 104 text

GATT for generic commands Electronic Stimulation Control Characteristic UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Properties: Write Value: 1 byte

Slide 105

Slide 105 text

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 - OnOff the right channels - OnOff the left channels

Slide 106

Slide 106 text

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 - OnOff the right channels - OnOff the left channels

Slide 107

Slide 107 text

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: OnOff the left channels - 11: OnOff the right channels

Slide 108

Slide 108 text

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: OnOff the left channels - 11: OnOff the right channels

Slide 109

Slide 109 text

How to define GATT

Slide 110

Slide 110 text

How to define GATT 1. Create UUID for the service & characteristic

Slide 111

Slide 111 text

How to define GATT 1. Create UUID for the service & characteristic $ uuidgen CEEA31BC-BEAC-4A78-B7ED-FC96B6254D4C

Slide 112

Slide 112 text

How to define GATT 1. Create UUID for the service & characteristic 2. Define the properties (Read, Notify, Write, etc.) $ uuidgen CEEA31BC-BEAC-4A78-B7ED-FC96B6254D4C

Slide 113

Slide 113 text

How to define GATT 1. 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

Slide 114

Slide 114 text

How to define GATT 1. 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

Slide 115

Slide 115 text

How to define GATT 1. 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

Slide 116

Slide 116 text

Reference: GATT profiles by Bluetooth SIG

Slide 117

Slide 117 text

Defining background behaviors

Slide 118

Slide 118 text

Background behaviors on iOS • Very limited - Listening to music - Getting location data - Downloading data

Slide 119

Slide 119 text

Imagine

Slide 120

Slide 120 text

If BLE didn’t work in the background…

Slide 121

Slide 121 text

No content

Slide 122

Slide 122 text

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

Slide 123

Slide 123 text

No content

Slide 124

Slide 124 text

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

Slide 125

Slide 125 text

What functions can be used in the background?

Slide 126

Slide 126 text

What functions can be used in the background? • Scanning peripherals

Slide 127

Slide 127 text

What functions can be used in the background? • Scanning peripherals • Connecting with peripherals

Slide 128

Slide 128 text

What functions can be used in the background? • Scanning peripherals • Connecting with peripherals • Reading characteristics’ value

Slide 129

Slide 129 text

What functions can be used in the background? • Scanning peripherals • Connecting with peripherals • Reading characteristics’ value • Writing characteristics’ value

Slide 130

Slide 130 text

What functions can be used in the background? • Scanning peripherals • Connecting with peripherals • Reading characteristics’ value • Writing characteristics’ value • Receiving notifications

Slide 131

Slide 131 text

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!

Slide 132

Slide 132 text

How to support background mode

Slide 133

Slide 133 text

No content

Slide 134

Slide 134 text

Just check this box!

Slide 135

Slide 135 text

Limitations

Slide 136

Slide 136 text

Limitations • Longer intervals for scanning

Slide 137

Slide 137 text

Limitations • Longer intervals for scanning • Must explicitly specify one or more services to scan

Slide 138

Slide 138 text

Limitations • Longer intervals for scanning • Must explicitly specify one or more services to scan • CBCentralManagerOptionShowPowerAlertKey option is ignored

Slide 139

Slide 139 text

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)

Slide 140

Slide 140 text

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

Slide 141

Slide 141 text

No content

Slide 142

Slide 142 text

State Preservation and Restoration

Slide 143

Slide 143 text

State Preservation and Restoration The system takes over the BLE tasks even after the app is killed.

Slide 144

Slide 144 text

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.

Slide 145

Slide 145 text

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.

Slide 146

Slide 146 text

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!

Slide 147

Slide 147 text

No content

Slide 148

Slide 148 text

• The app is killed by the system

Slide 149

Slide 149 text

• The app is killed by the system • The user pushes the button on the peripheral device

Slide 150

Slide 150 text

• The app is killed by the system • The user pushes the button on the peripheral device • The system receives the notification

Slide 151

Slide 151 text

• 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.

Slide 152

Slide 152 text

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.

Slide 153

Slide 153 text

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!

Slide 154

Slide 154 text

Implementation • Add an option when initializing the CBCentralManager object. let options = [ CBCentralManagerOptionRestoreIdentifierKey: "somekey" ] centralManager = CBCentralManager( delegate: self, queue: queue, options: options)

Slide 155

Slide 155 text

Implementation • Implement the delegate method which is called when the app is restored. func centralManager(central: CBCentralManager, willRestoreState dict: [String : AnyObject]) { print("Restored") }

Slide 156

Slide 156 text

Testing the restoration • Kill the app as if it was killed by the iOS kill(getpid(), SIGKILL);

Slide 157

Slide 157 text

How to test without HW prototypes

Slide 158

Slide 158 text

Did the HW prototypes exist when develop the apps? Projects HW prototypes existed? Moff YES WHILL NO BONX NO SmartDrive YES PLEN2 NO Music for the Deaf NO

Slide 159

Slide 159 text

Development Kit

Slide 160

Slide 160 text

Development Kit BLE Module

Slide 161

Slide 161 text

Development Kit BLE Module Display

Slide 162

Slide 162 text

Development Kit BLE Module Display USB interface

Slide 163

Slide 163 text

Development Kit BLE Module Display USB interface Battery box

Slide 164

Slide 164 text

Development Kit Can start development without creating a circuit ourselves BLE Module Display USB interface Battery box

Slide 165

Slide 165 text

No content

Slide 166

Slide 166 text

Development Kit

Slide 167

Slide 167 text

Development Kit App

Slide 168

Slide 168 text

Development Kit App BLE

Slide 169

Slide 169 text

Horizontal (-100~100) / Vertical (-100~100) Development Kit App BLE

Slide 170

Slide 170 text

No content

Slide 171

Slide 171 text

Emulator App • Develop another iOS app as the alternative to the peripheral device • Use CBPeripheralManager • Easier for iOS engineers

Slide 172

Slide 172 text

No content

Slide 173

Slide 173 text

No content

Slide 174

Slide 174 text

No content

Slide 175

Slide 175 text

=

Slide 176

Slide 176 text

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

Slide 177

Slide 177 text

Troubleshooting

Slide 178

Slide 178 text

Can’t find the peripheral Scan ?

Slide 179

Slide 179 text

Can’t connect Find

Slide 180

Slide 180 text

Can’t connect Connect ×

Slide 181

Slide 181 text

• Connection dropped • Can’t discover services or characteristics • Fail to write • Incorrect characteristic values • Incorrect behaviors in the background • etc…

Slide 182

Slide 182 text

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’

Slide 183

Slide 183 text

Can’t find the peripheral • Scanning, but can’t find the peripheral device

Slide 184

Slide 184 text

Can’t find the peripheral • Scanning, but can’t find the peripheral device Scan

Slide 185

Slide 185 text

Can’t find the peripheral • Scanning, but can’t find the peripheral device Scan but ‘didDiscover’ method isn’t called

Slide 186

Slide 186 text

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

Slide 187

Slide 187 text

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

Slide 188

Slide 188 text

Can’t connect, etc. Connect

Slide 189

Slide 189 text

Can’t connect, etc. Connect Services & Characteristics

Slide 190

Slide 190 text

Other debugging tools

Slide 191

Slide 191 text

Bluetooth Explorer An OS X app made by Apple

Slide 192

Slide 192 text

No content

Slide 193

Slide 193 text

Low Energy Devices

Slide 194

Slide 194 text

Low Energy Devices Scan, Connect

Slide 195

Slide 195 text

Low Energy Devices Scan, Connect Details of services and characteristics

Slide 196

Slide 196 text

Low Energy Devices Scan, Connect Details of services and characteristics Write, Read, Register Notify (Subscribe)

Slide 197

Slide 197 text

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

Slide 198

Slide 198 text

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

Slide 199

Slide 199 text

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

Slide 200

Slide 200 text

func centralManager( central: CBCentralManager, didDiscoverPeripheral peripheral: CBPeripheral, advertisementData: [String : AnyObject], RSSI: NSNumber!) { print(advertisementData) } Filtered by iOS! e.g. Can’t see the ‘Manufacture Data’ field of iBeacon → Can’t see all of the advertisement data

Slide 201

Slide 201 text

No content

Slide 202

Slide 202 text

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

Slide 203

Slide 203 text

Packet Logger An OS X app made by Apple

Slide 204

Slide 204 text

No content

Slide 205

Slide 205 text

No content

Slide 206

Slide 206 text

How to get

Slide 207

Slide 207 text

How to get

Slide 208

Slide 208 text

How to get Download ‘Hardware IO Tools for Xcode’

Slide 209

Slide 209 text

How to get Download ‘Hardware IO Tools for Xcode’

Slide 210

Slide 210 text

How to get Download ‘Hardware IO Tools for Xcode’

Slide 211

Slide 211 text

How to get Download ‘Hardware IO Tools for Xcode’

Slide 212

Slide 212 text

App Review

Slide 213

Slide 213 text

No content

Slide 214

Slide 214 text

MSRP $13,995

Slide 215

Slide 215 text

Costing too much

Slide 216

Slide 216 text

Not enough devices when submitting

Slide 217

Slide 217 text

Videos for review

Slide 218

Slide 218 text

Videos for review • Show how the app works with the peripheral device

Slide 219

Slide 219 text

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

Slide 220

Slide 220 text

No content

Slide 221

Slide 221 text

No content

Slide 222

Slide 222 text

• Shoot with iPhone

Slide 223

Slide 223 text

• Shoot with iPhone • Edit with iMovie

Slide 224

Slide 224 text

Recap

Slide 225

Slide 225 text

Recap • What is Bluetooth Low Energy?

Slide 226

Slide 226 text

Recap • What is Bluetooth Low Energy? • Basics of Core Bluetooth with an actual product

Slide 227

Slide 227 text

Recap • What is Bluetooth Low Energy? • Basics of Core Bluetooth with an actual product • Practical Core Bluetooth with specific examples

Slide 228

Slide 228 text

Recap • What is Bluetooth Low Energy? • Basics of Core Bluetooth with an actual product • Practical Core Bluetooth with specific examples - Defining GATT

Slide 229

Slide 229 text

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

Slide 230

Slide 230 text

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

Slide 231

Slide 231 text

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

Slide 232

Slide 232 text

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

Slide 233

Slide 233 text

Resources

Slide 234

Slide 234 text

ଋɿ31mm ද 4 ද 1 iOSʷBLE Core Bluetooth ϓϩάϥ ϛ ϯά iOSʷBLE Core Bluetooth ϓ ϩ ά ϥ ϛ ϯ ά అ म Ұ দ ଜ ྱ ԝ ử ஶ అमҰʷদଜྱԝ ʹ ஶ Shuichi TSUTSUMI ʷ Reo MATSUMURA iOSʷBLE Core Bluetooth Programming iOSʷBLE 定価:本体4,000円 (税別) Resources

Slide 235

Slide 235 text

ଋɿ31mm ද 4 ද 1 iOSʷBLE Core Bluetooth ϓϩάϥ ϛ ϯά iOSʷBLE Core Bluetooth ϓ ϩ ά ϥ ϛ ϯ ά అ म Ұ দ ଜ ྱ ԝ ử ஶ అमҰʷদଜྱԝ ʹ ஶ Shuichi TSUTSUMI ʷ Reo MATSUMURA iOSʷBLE Core Bluetooth Programming iOSʷBLE 定価:本体4,000円 (税別) Resources • 500 pages about iOS x BLE

Slide 236

Slide 236 text

ଋɿ31mm ද 4 ද 1 iOSʷBLE Core Bluetooth ϓϩάϥ ϛ ϯά iOSʷBLE Core Bluetooth ϓ ϩ ά ϥ ϛ ϯ ά అ म Ұ দ ଜ ྱ ԝ ử ஶ అमҰʷদଜྱԝ ʹ ஶ Shuichi TSUTSUMI ʷ Reo MATSUMURA iOSʷBLE Core Bluetooth Programming iOSʷBLE 定価:本体4,000円 (税別) Resources • 500 pages about iOS x BLE • Japanese only

Slide 237

Slide 237 text

Resources

Slide 238

Slide 238 text

Resources • Getting Started with Bluetooth Low Energy - Covers large area of BLE

Slide 239

Slide 239 text

Resources • Getting Started with Bluetooth Low Energy - Covers large area of BLE • Core Bluetooth Programming Guide - Good to know the overview of Core Bluetooth • Core Bluetooth Framework Reference - Details of Core Bluetooth

Slide 240

Slide 240 text

Resources • Getting Started with Bluetooth Low Energy - Covers large area of BLE • Core Bluetooth Programming Guide - Good to know the overview of Core Bluetooth • Core Bluetooth Framework Reference - Details of Core Bluetooth • Bluetooth Accessory Design Guidelines for Apple Products - For HW side, but helpful also for iOS engineers to know specs or limitations due to HW side such as connection intervals.

Slide 241

Slide 241 text

Resources

Slide 242

Slide 242 text

Resources • WWDC 2012 - Session 703 - Core Bluetooth 101 - Helpful to know about BLE

Slide 243

Slide 243 text

Resources • WWDC 2012 - Session 703 - Core Bluetooth 101 - Helpful to know about BLE • WWDC 2012 - Session 705 - Advanced Core Bluetooth - Connection interval, Caching, etc… • WWDC 2013 - Session 703 - Core Bluetooth - Retrieving peripherals, State preservation & restoration etc.. - Includes advanced and detailed information

Slide 244

Slide 244 text

Resources • WWDC 2012 - Session 703 - Core Bluetooth 101 - Helpful to know about BLE • WWDC 2012 - Session 705 - Advanced Core Bluetooth - Connection interval, Caching, etc… • WWDC 2013 - Session 703 - Core Bluetooth - Retrieving peripherals, State preservation & restoration etc.. - Includes advanced and detailed information • Bluetooth Core Specification by Bluetooth SIG - The official specification / Total 2000 pages…

Slide 245

Slide 245 text

Thank you! Shuichi Tsutsumi - iOS Freelancer • Twitter: @shu223 • GitHub: shu223 • Blog: https://medium.com/@shu223/ • Email: shuichi0526@gmail.com