Core Bluetooth - Apple Inc. · 2016. 7. 10. · Evolution of Core Bluetooth Core Bluetooth in iOS 7...

Preview:

Citation preview

These are confidential sessions—please refrain from streaming, blogging, or taking pictures

Session 703

Core Bluetooth

Jason ConnCode Monkey & Radio Sponge

Brian TuckerBluetooth SIG Grand Wizard

Renaud LienhartKeeper of the Code & General Curmudgeon

BLE State of the Union

Evolution of Core Bluetooth

Core Bluetooth in iOS 7

Code Demo

Tips and Best Practices

BLE State of the Union

Evolution of Core Bluetooth

Core Bluetooth in iOS 7

Code Demo

Tips and Best Practices

BLE State of the Union

Evolution of Core Bluetooth

Core Bluetooth in iOS 7

Code Demo

Tips and Best Practices

BLE State of the Union

Evolution of Core Bluetooth

Core Bluetooth in iOS 7

Code Demo

Tips and Best Practices

BLE State of the Union

Evolution of Core Bluetooth

Core Bluetooth in iOS 7

Code Demo

Tips and Best Practices

BLE State of the Union

Evolution of Core Bluetooth

Core Bluetooth in iOS 7

Code Demo

Tips and Best Practices

BLE: State of the Union

Brian TuckerBluetooth SIG Grand Wizard

Source ABI Research 2013

Projected BLE Accessories Shipped1 Billion+

Projected BLE Accessories Shipped

0

750

1,500

2,250

3,000

2012 2013 2014 2015 2016 2017 2018

Source ABI Research 2013

1,009,000,000 Devices

Proximity

Security

Automation

Health Care Sports/Fitness

Entertainment Toys

Pay Systems Time Services

Evolution of Core Bluetooth

Renaud LienhartKeeper of the Code & General Curmudgeon

Observer, Central, Client

• CBCentralManager■ Discover peripherals■ Connect

• CBPeripheral■ Access remote services

iOS 5

Broadcaster, Peripheral, ServeriOS 6

• CBPeripheralManager■ Host services■ Advertise information■ Field CBCentral requests

• Peripheral database caching

LE, EvolvedCore Bluetooth in iOS 7.0

Ch-ch-ch-changes

• Simpler device management• Smarter peripherals• Performance improvements•Application persistence• Built-in services

What’s New

That is the questionTo Simulate, or Not to Simulate

• Emerging market • Limited hardware available

■ No iOS devices

•Development difficult

That is the questionTo Simulate, or Not to Simulate

• Exploding market•Many LE-compatible devices

■ All iOS hardware■ Macbook, Mac mini

• Third-party development kits

That is the questionTo Simulate, or Not to Simulate

• Exploding market•Many LE-compatible devices

■ All iOS hardware■ Macbook, Mac mini

• Third-party development kits

That is the questionTo Simulate, or Not to Simulate

• Exploding market•Many LE-compatible devices

■ All iOS hardware■ Most Mac hardware

• Third-party development kits

Handling centrals and peripheralsSimpler Device Management

• Bye, bye CoreFoundation

Handling centrals and peripheralsSimpler Device Management

@property(readonly, nonatomic) CFUUIDRef *UUID;

• Bye, bye CoreFoundation

Handling centrals and peripheralsSimpler Device Management

@property(readonly, nonatomic) CFUUIDRef *UUID;

@property(readonly, nonatomic) NSUUID *identifier;

• Bye, bye CoreFoundation

Handling centrals and peripheralsSimpler Device Management

@property(readonly, nonatomic) CFUUIDRef *UUID;

@property(readonly, nonatomic) NSUUID *identifier;

• Identifiers created at discovery

Retrieving peripherals, todaySimpler Device Management

CBCentralManager <CBCentralManagerDelegate>

Retrieving peripherals, todaySimpler Device Management

CBCentralManager <CBCentralManagerDelegate>

Retrieving peripherals, todaySimpler Device Management

retrievePeripherals:

CBCentralManager <CBCentralManagerDelegate>

Retrieving peripherals, todaySimpler Device Management

didRetrievePeripherals:

retrievePeripherals:

CBCentralManager <CBCentralManagerDelegate>

Retrieving peripherals, todaySimpler Device Management

didRetrievePeripherals:

retrievePeripherals:

CBCentralManager <CBCentralManagerDelegate>

retrieveConnectedPeripherals

Retrieving peripherals, todaySimpler Device Management

didRetrievePeripherals:

retrievePeripherals:

CBCentralManager <CBCentralManagerDelegate>

retrieveConnectedPeripherals

didRetrieveConnectedPeripherals:

Retrieving peripheralsSimpler Device Management

CBCentralManager <CBCentralManagerDelegate>

Retrieving peripheralsSimpler Device Management

CBCentralManager <CBCentralManagerDelegate>

Retrieving peripheralsSimpler Device Management

retrievePeripheralsWithIdentifiers:

CBCentralManager <CBCentralManagerDelegate>

Retrieving peripheralsSimpler Device Management

retrievePeripheralsWithIdentifiers:

CBCentralManager <CBCentralManagerDelegate>

didRetrievePeripherals:

Retrieving peripheralsSimpler Device Management

CBCentralManager

retrievePeripheralsWithIdentifiers:

<CBCentralManagerDelegate>

, the iOS 7 way

Retrieving peripheralsSimpler Device Management

CBCentralManager

retrievePeripheralsWithIdentifiers:

retrieveConnectedPeripheralsWithServices:

<CBCentralManagerDelegate>

, the iOS 7 way

Retrieving peripheralsSimpler Device Management

CBCentralManager

retrievePeripheralsWithIdentifiers:

retrieveConnectedPeripheralsWithServices:

connectPeripheral:options:

<CBCentralManagerDelegate>

, the iOS 7 way

Smarter Peripherals

Smarter Peripherals

•More connection-aware@property(readonly) BOOL isConnected;

typedef NS_ENUM(NSInteger, CBPeripheralState) { CBPeripheralStateDisconnected = 0, CBPeripheralStateConnecting, CBPeripheralStateConnected };

@property(readonly) CBPeripheralState state;

Smarter Peripherals

•More connection-aware@property(readonly) BOOL isConnected;

typedef NS_ENUM(NSInteger, CBPeripheralState) { CBPeripheralStateDisconnected = 0, CBPeripheralStateConnecting, CBPeripheralStateConnected };

@property(readonly) CBPeripheralState state;

Smarter Peripherals

Smarter Peripherals

• Better service invalidation

Smarter Peripherals

• Better service invalidation(void)peripheralDidInvalidateServices:(CBPeripheral *)

Smarter Peripherals

• Better service invalidation(void)peripheralDidInvalidateServices:(CBPeripheral *)

(void)peripheral:(CBPeripheral *)didModifyServices:(NSArray *)

LE, EvolvedCore Bluetooth in iOS 7.0

Jason ConnCode Monkey & Radio Sponge

Performance Improvements

ServiceHeart Rate Monitor

CharacteristicHeart Rate Measurement

Database caching, todayPerformance Improvements

ServiceHeart Rate Monitor

CharacteristicHeart Rate Measurement

ServiceHeart Rate Monitor

CharacteristicHeart Rate Measurement

Characteristic Value190

DescriptorClient Configuration

Database caching, todayPerformance Improvements

• Introduced in iOS 6 ServiceHeart Rate Monitor

CharacteristicHeart Rate Measurement

ServiceHeart Rate Monitor

CharacteristicHeart Rate Measurement

Characteristic Value190

DescriptorClient Configuration

Database caching, todayPerformance Improvements

• Introduced in iOS 6• Increases speed and battery life

ServiceHeart Rate Monitor

CharacteristicHeart Rate Measurement

ServiceHeart Rate Monitor

CharacteristicHeart Rate Measurement

Characteristic Value190

DescriptorClient Configuration

Database caching, todayPerformance Improvements

• Introduced in iOS 6• Increases speed and battery life• Cache services and characteristics

ServiceHeart Rate Monitor

CharacteristicHeart Rate Measurement

ServiceHeart Rate Monitor

CharacteristicHeart Rate Measurement

Characteristic Value190

DescriptorClient Configuration

Database caching, in iOS 7Performance Improvements

ServiceHeart Rate Monitor

CharacteristicHeart Rate Measurement

DescriptorClient Configuration

DescriptorClient Configuration

Characteristic Value190

Characteristic Value190

Characteristic Value73

Characteristic Value190

• Cache characteristic descriptors

Database caching, in iOS 7Performance Improvements

ServiceHeart Rate Monitor

CharacteristicHeart Rate Measurement

DescriptorClient Configuration

DescriptorClient Configuration

Characteristic Value190

Characteristic Value190

Characteristic Value73

Characteristic Value190

• Cache characteristic descriptors• Caching for characteristic values?

Database caching, in iOS 7Performance Improvements

ServiceHeart Rate Monitor

CharacteristicHeart Rate Measurement

DescriptorClient Configuration

DescriptorClient Configuration

Characteristic Value190

Characteristic Value190

Characteristic Value73

Characteristic Value190

• Cache characteristic descriptors• Caching for characteristic values?

Database caching, in iOS 7Performance Improvements

ServiceHeart Rate Monitor

CharacteristicHeart Rate Measurement

DescriptorClient Configuration

DescriptorClient Configuration

Characteristic Value190

Characteristic Value190

Characteristic Value73

Characteristic Value190

• Cache characteristic descriptors• Caching for characteristic values?

■ Provide last-known characteristic values and descriptor values

Database caching, in iOS 7Performance Improvements

ServiceHeart Rate Monitor

CharacteristicHeart Rate Measurement

DescriptorClient Configuration

DescriptorClient Configuration

Characteristic Value190

Characteristic Value190

Characteristic Value73

Characteristic Value190

Characteristic Value73

• Cache characteristic descriptors• Caching for characteristic values?

■ Provide last-known characteristic values and descriptor values

• Free!

Database caching, in iOS 7Performance Improvements

ServiceHeart Rate Monitor

CharacteristicHeart Rate Measurement

DescriptorClient Configuration

DescriptorClient Configuration

Characteristic Value190

Characteristic Value190

Characteristic Value73

Characteristic Value190

Characteristic Value73

Performance Improvements

Sending dataPerformance Improvements

115 BPM

Sending dataPerformance Improvements

115 BPM

Sending dataPerformance Improvements

115 BPM

Sending dataPerformance Improvements

115 BPM

Sending dataPerformance Improvements

115 BPM

Sending dataPerformance Improvements

Mon Tues Weds Thurs

58

70

43

55

96

53

26

17

Mon Tues Weds Thurs

50%

28%

14%9%

115 BPM

Sending dataPerformance Improvements

Mon Tues Weds Thurs

58

70

43

55

96

53

26

17

Mon Tues Weds Thurs

50%

28%

14%9%

Sending dataPerformance Improvements

Sending dataPerformance Improvements

• Support MTU exchange request

Sending dataPerformance Improvements

• Support MTU exchange request•Maximum amount of data per PDU

Sending dataPerformance Improvements

• Support MTU exchange request•Maximum amount of data per PDU• Send more data at a time

Sending dataPerformance Improvements

Sending data

Default MTU23 bytes

Performance Improvements

Sending data

Default MTU23 bytes

Performance Improvements

Sending data

Default MTU23 bytes

Increased MTU??? bytes

Performance Improvements

Sending data

Default MTU23 bytes

Increased MTU??? bytes

Performance Improvements

Sending dataPerformance Improvements

Sending dataPerformance Improvements

•When central, ask for larger MTU

Sending dataPerformance Improvements

•When central, ask for larger MTU•Up to 20% increase in throughput

Sending dataPerformance Improvements

•When central, ask for larger MTU•Up to 20% increase in throughput• Free!

Performing long-term actionsPerformance Improvements

Performing long-term actionsPerformance Improvements

Living in a multitasking worldPerforming Long-Term Actions

Living in a multitasking worldPerforming Long-Term Actions

• Backgrounding modes

Living in a multitasking worldPerforming Long-Term Actions

• Backgrounding modes■ App communicates using CoreBluetooth

Living in a multitasking worldPerforming Long-Term Actions

• Backgrounding modes■ App communicates using CoreBluetooth■ App shares data using CoreBluetooth

Living in a multitasking worldPerforming Long-Term Actions

• Backgrounding modes■ App communicates using CoreBluetooth■ App shares data using CoreBluetooth

• Background applications can be terminated by system

Living in a multitasking worldPerforming Long-Term Actions

• Backgrounding modes■ App communicates using CoreBluetooth■ App shares data using CoreBluetooth

• Background applications can be terminated by system• Some use-cases take hours

Our solutionPerforming Long-term Actions

Our solutionPerforming Long-term Actions

• System watches application state

Our solutionPerforming Long-term Actions

• System watches application state•When application is terminated…

Our solutionPerforming Long-term Actions

• System watches application state•When application is terminated…

■ If cause is memory pressure

Our solutionPerforming Long-term Actions

• System watches application state•When application is terminated…

■ If cause is memory pressure■ If application is performing long-term action(s)

Our solutionPerforming Long-term Actions

• System watches application state•When application is terminated…

■ If cause is memory pressure■ If application is performing long-term action(s)

• System acts as application proxy

Our solutionPerforming Long-term Actions

• System watches application state•When application is terminated…

■ If cause is memory pressure■ If application is performing long-term action(s)

• System acts as application proxy•When needed, application is re-launched

State Preservation and Restoration

State Preservation and Restoration

•Opt-in

State Preservation and Restoration

•Opt-in• Supported by CBCentralManager and CBPeripheralManager

State Preservation and Restoration

•Opt-in• Supported by CBCentralManager and CBPeripheralManager•Minimal implementation

■ Provide unique “identifier” for manager■ Implement new delegate method

A picture is worth a thousand wordsState Preservation and Restoration

A picture is worth a thousand wordsState Preservation and Restoration

• Snapshot taken before termination

A picture is worth a thousand wordsState Preservation and Restoration

• Snapshot taken before termination• CBCentralManager

A picture is worth a thousand wordsState Preservation and Restoration

• Snapshot taken before termination• CBCentralManager

■ Scanning state

A picture is worth a thousand wordsState Preservation and Restoration

• Snapshot taken before termination• CBCentralManager

■ Scanning state■ Pending/active connections

A picture is worth a thousand wordsState Preservation and Restoration

• Snapshot taken before termination• CBCentralManager

■ Scanning state■ Pending/active connections■ Peripheral subscriptions

A picture is worth a thousand wordsState Preservation and Restoration

• Snapshot taken before termination• CBCentralManager

■ Scanning state■ Pending/active connections■ Peripheral subscriptions

• CBPeripheralManager

A picture is worth a thousand wordsState Preservation and Restoration

• Snapshot taken before termination• CBCentralManager

■ Scanning state■ Pending/active connections■ Peripheral subscriptions

• CBPeripheralManager■Advertising state

A picture is worth a thousand wordsState Preservation and Restoration

• Snapshot taken before termination• CBCentralManager

■ Scanning state■ Pending/active connections■ Peripheral subscriptions

• CBPeripheralManager■Advertising state■ Published services

A picture is worth a thousand wordsState Preservation and Restoration

• Snapshot taken before termination• CBCentralManager

■ Scanning state■ Pending/active connections■ Peripheral subscriptions

• CBPeripheralManager■Advertising state■ Published services■Central subscriptions

Back from the deadState Preservation and Restoration

Back from the deadState Preservation and Restoration

Back from the deadState Preservation and Restoration

• Events that system can’t handle trigger application re-launch

Back from the deadState Preservation and Restoration

• Events that system can’t handle trigger application re-launch■ Peripheral connects, central subscribes, notification received, etc.

Back from the deadState Preservation and Restoration

• Events that system can’t handle trigger application re-launch■ Peripheral connects, central subscribes, notification received, etc.

•Application re-launched into background, running

Back from the deadState Preservation and Restoration

• Events that system can’t handle trigger application re-launch■ Peripheral connects, central subscribes, notification received, etc.

•Application re-launched into background, running■ Re-instantiates appropriate manager object(s)

Back from the deadState Preservation and Restoration

• Events that system can’t handle trigger application re-launch■ Peripheral connects, central subscribes, notification received, etc.

•Application re-launched into background, running■ Re-instantiates appropriate manager object(s)■ Delegate callback provides all preserved state

Back from the deadState Preservation and Restoration

• Events that system can’t handle trigger application re-launch■ Peripheral connects, central subscribes, notification received, etc.

•Application re-launched into background, running■ Re-instantiates appropriate manager object(s)■ Delegate callback provides all preserved state■ Power on event

Back from the deadState Preservation and Restoration

• Events that system can’t handle trigger application re-launch■ Peripheral connects, central subscribes, notification received, etc.

•Application re-launched into background, running■ Re-instantiates appropriate manager object(s)■ Delegate callback provides all preserved state■ Power on event■ Delegate callback for triggering event

DemoAdding State Preservation and Restoration Support

Jason ConnCode Monkey & Radio Sponge

Bluetooth Low Energy graduatesBuilt-in Services

Renaud LienhartKeeper of the Code & General Curmudgeon

GATT ClientBuilt-in Services

GATT ClientBuilt-in Services

•HID Over GATT Profile ■ HID, Battery, Device Information services

GATT ClientBuilt-in Services

•HID Over GATT Profile ■ HID, Battery, Device Information services

•Works just like Bluetooth Classic■ Managed from Bluetooth Settings■ iOS automatically reconnects paired peripherals

GATT ServerBuilt-in Services

GATT ServerBuilt-in Services

• Battery Service

GATT ServerBuilt-in Services

• Battery Service• Current Time Service

■ Accurate time and date■ Time zone information

GATT ServerBuilt-in Services

• Battery Service• Current Time Service

■ Accurate time and date■ Time zone information

•One more thing…

Notifications—the problemsBuilt-in Services

Notifications—the problemsBuilt-in Services

•Message Access Profile (MAP)

Notifications—the problemsBuilt-in Services

•Message Access Profile (MAP)■ Developed for an automotive usage

Notifications—the problemsBuilt-in Services

•Message Access Profile (MAP)■ Developed for an automotive usage■ Very constrained: SMS, MMS, Email

Notifications—the problemsBuilt-in Services

•Message Access Profile (MAP)■ Developed for an automotive usage■ Very constrained: SMS, MMS, Email

•Alert Notification Service

Notifications—the problemsBuilt-in Services

•Message Access Profile (MAP)■ Developed for an automotive usage■ Very constrained: SMS, MMS, Email

•Alert Notification Service■ Very limited

Notifications—the problemsBuilt-in Services

•Message Access Profile (MAP)■ Developed for an automotive usage■ Very constrained: SMS, MMS, Email

•Alert Notification Service■ Very limited

• Custom app tailored to a specific accessory

Notifications—the problemsBuilt-in Services

•Message Access Profile (MAP)■ Developed for an automotive usage■ Very constrained: SMS, MMS, Email

•Alert Notification Service■ Very limited

• Custom app tailored to a specific accessory■ Heavyweight

Notifications—the problemsBuilt-in Services

•Message Access Profile (MAP)■ Developed for an automotive usage■ Very constrained: SMS, MMS, Email

•Alert Notification Service■ Very limited

• Custom app tailored to a specific accessory■ Heavyweight■ Data limited to what the sandbox allows

Notifications—our solutionBuilt-in Services

Notifications—our solutionBuilt-in Services

•Apple Notification Center Service

Notifications—our solutionBuilt-in Services

•Apple Notification Center Service■ Apple-specific

Notifications—our solutionBuilt-in Services

•Apple Notification Center Service■ Apple-specific■ Notification about any events on your phone

Notifications—our solutionBuilt-in Services

•Apple Notification Center Service■ Apple-specific■ Notification about any events on your phone

■ Incoming and Missed calls, Voicemails

Notifications—our solutionBuilt-in Services

•Apple Notification Center Service■ Apple-specific■ Notification about any events on your phone

■ Incoming and Missed calls, Voicemails■ Instant messages, Emails

Notifications—our solutionBuilt-in Services

•Apple Notification Center Service■ Apple-specific■ Notification about any events on your phone

■ Incoming and Missed calls, Voicemails■ Instant messages, Emails■ Calendar alerts

Notifications—our solutionBuilt-in Services

•Apple Notification Center Service■ Apple-specific■ Notification about any events on your phone

■ Incoming and Missed calls, Voicemails■ Instant messages, Emails■ Calendar alerts■ App notifications

Notifications—our solutionBuilt-in Services

•Apple Notification Center Service■ Apple-specific■ Notification about any events on your phone

■ Incoming and Missed calls, Voicemails■ Instant messages, Emails■ Calendar alerts■ App notifications

■ System automatically reconnects

Notifications—our solutionBuilt-in Services

•Apple Notification Center Service■ Apple-specific■ Notification about any events on your phone

■ Incoming and Missed calls, Voicemails■ Instant messages, Emails■ Calendar alerts■ App notifications

■ System automatically reconnects ■ Detailed specification posted on the developer portal soon

Apple Notification Center ServiceBuilt-in Services

New iMessage

New iMessageNew Social Notification, UID=1

New iMessageNew Social Notification, UID=1

GetAttributes(UID=1,Title,Msg)

New iMessageNew Social Notification, UID=1

GetAttributes(UID=1,Title,Msg)

Title=”Jason”,Msg=”Beers?”

New iMessageNew Social Notification, UID=1

GetAttributes(UID=1,Title,Msg)

Title=”Jason”,Msg=”Beers?”

Alert User

New iMessageNew Social Notification, UID=1

GetAttributes(UID=1,Title,Msg)

Title=”Jason”,Msg=”Beers?”

iMessage Read

Alert User

New iMessageNew Social Notification, UID=1

GetAttributes(UID=1,Title,Msg)

Title=”Jason”,Msg=”Beers?”

iMessage Read Notification Removed, UID=1

Alert User

New iMessageNew Social Notification, UID=1

GetAttributes(UID=1,Title,Msg)

Title=”Jason”,Msg=”Beers?”

iMessage Read Notification Removed, UID=1

Alert User

Dismiss Alert

Tips and Best Practices

Tips and Best Practices

• Core Bluetooth needs to know if you intend to use CBPeripherals—keep a reference to them

Tips and Best Practices

• Core Bluetooth needs to know if you intend to use CBPeripherals—keep a reference to them• Scanning and connection requests do not time out

Tips and Best Practices

• Core Bluetooth needs to know if you intend to use CBPeripherals—keep a reference to them• Scanning and connection requests do not time out• CBPeripheral and CBCentral conform to NSCopying and can be used as dictionary keys

Tips and Best Practices

• Core Bluetooth needs to know if you intend to use CBPeripherals—keep a reference to them• Scanning and connection requests do not time out• CBPeripheral and CBCentral conform to NSCopying and can be used as dictionary keys•Do not touch Client Configuration Characteristic Descriptors directly

Tips and Best Practices

• Core Bluetooth needs to know if you intend to use CBPeripherals—keep a reference to them• Scanning and connection requests do not time out• CBPeripheral and CBCentral conform to NSCopying and can be used as dictionary keys•Do not touch Client Configuration Characteristic Descriptors directly•Do not game the background mechanisms

Bluetooth best practices

http://developer.apple.com/hardwaredrivers/BluetoothDesignGuidelines.pdf

Apple Guidelines

Core Bluetooth Programming Guide

Finally!

Apple Guidelines

Craig KeithleyMFi & I/O Technology Evangelistkeithley@apple.com

Stephen ChickiPhone Evangelismchick@apple.com

Developer ProgramsMFi Programhttp://developer.apple.com/mfi/

More Information

Bluetooth Accessory Design Guidelineshttp://developer.apple.com/hardwaredrivers/BluetoothDesignGuidelines.pdf

Reporting Bugshttp://bugreport.apple.com

Apple Developer Forumshttps://devforums.apple.com/community/ios/core/cbthttps://devforums.apple.com/community/mac/coreos/cbt

Bluetooth Developer Sitehttp://developer.bluetooth.org

More Information

What’s New in Core Location PresidioThursday 11:30AM

Related Sessions

Designing Accessories for iOS and OS X Nob HillTuesday 10:15AM

Labs

iOS and OS X Accessories Lab Core OS Lab BThursday 9:00AM

iOS and OS X Accessories Lab Core OS Lab ATuesday 11:30AM

ProximitySecurityAutomationHealth CareSports/FitnessEntertainmentToysPay Systems

Proximity

Security

Automation

Health Care Sports/Fitness

Entertainment

Toys

Pay Systems

Proximity

Security

Automation

Health Care Sports/Fitness

Entertainment

Toys

Pay Systems

Connect the World

Recommended