126
#WWDC17 © 2017 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple. Craig Dooley, Bluetooth Engineer Duy Phan, Bluetooth Engineer What’s New in Core Bluetooth Session 712 System Frameworks

•What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Embed Size (px)

Citation preview

Page 1: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

#WWDC17

© 2017 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple.

Craig Dooley, Bluetooth Engineer Duy Phan, Bluetooth Engineer

•What’s New in Core Bluetooth • Session 712

System Frameworks

Page 2: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

•Introduction •Enhanced reliability •Platform support •L2CAP channels •Best practices •Getting the most out of Core Bluetooth

Page 3: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

•Introduction

Page 4: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed
Page 5: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed
Page 6: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed
Page 7: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed
Page 8: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed
Page 9: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed
Page 10: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Thank you!

Page 11: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Built-in Profiles

Apple Notification Center Service

Apple Media Service

MIDI over Bluetooth Low Energy

iBeacon

Current Time Service

HID Over GATT

Page 12: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Centrals and Peripherals

Page 13: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Centrals and Peripherals

Page 14: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Centrals and Peripherals

Page 15: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Centrals and Peripherals

Page 16: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

GATT Database

CBService

CBCharacteristic

CBCharacteristic

CBCharacteristic

CBService

CBCharacteristic

CBCharacteristic

CBCharacteristic

Page 17: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

GATT Database

CBService

CBCharacteristic

CBCharacteristic

CBCharacteristic

CBService

CBCharacteristic

CBCharacteristic

CBCharacteristic

Page 18: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

GATT Database

CBService

CBCharacteristic

CBCharacteristic

CBCharacteristic

CBService

CBCharacteristic

CBCharacteristic

CBCharacteristic

Page 19: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Reading Characteristics as a Central

Services can be read from a connected Central • Retrieve by identifier • Retrieve connected devices

open class CBCentralManager : CBManager { open func retrievePeripherals(withIdentifiers identifiers: [UUID]) -> [CBPeripheral] open func retrieveConnectedPeripherals(withServices serviceUUIDs: [CBUUID]) -> [CBPeripheral] }

Page 20: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

•Enhanced Reliability

Page 21: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Summary

Page 22: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

iOS Apps can continue using Core Bluetooth in the background

Backgrounded Apps

Page 23: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

iOS Apps can continue using Core Bluetooth in the background

Backgrounded Apps

Page 24: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Central operations can continue when your app is not running • Scan for new devices with services • Connect to an already known device

CBCentralManager restoration

Page 25: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

public let CBCentralManagerOptionRestoreIdentifierKey: String

/* * @seealso CBCentralManagerRestoredStatePeripheralsKey; * @seealso CBCentralManagerRestoredStateScanServicesKey; * @seealso CBCentralManagerRestoredStateScanOptionsKey; * */optional public func centralManager(_ central: CBCentralManager, willRestoreState dict: [String: Any])

Page 26: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Peripheral operations can continue when your app is not running • Publish local services • Advertise service UUID

CBPeripheralManager Restoration

Page 27: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

public let CBPeripheralManagerOptionRestoreIdentifierKey: String

/* * @seealso CBPeripheralManagerRestoredStateServicesKey; * @seealso CBPeripheralManagerRestoredStateAdvertisementDataKey; * */optional public func peripheralManager(_ peripheral: CBPeripheralManager, willRestoreState dict: [String: Any])

Page 28: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

State Preservation and RestorationNEW

Page 29: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

State Preservation and Restoration

Works across device reboot or Bluetooth system events

NEW

Page 30: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

State Preservation and Restoration

Works across device reboot or Bluetooth system events• Try to ask for as few system resources as possible

NEW

Page 31: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

State Preservation and Restoration

Works across device reboot or Bluetooth system events• Try to ask for as few system resources as possible• Background activities will be stopped if

NEW

Page 32: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

State Preservation and Restoration

Works across device reboot or Bluetooth system events• Try to ask for as few system resources as possible• Background activities will be stopped if

- User force quits the app

NEW

Page 33: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

State Preservation and Restoration

Works across device reboot or Bluetooth system events• Try to ask for as few system resources as possible• Background activities will be stopped if

- User force quits the app - User disables Bluetooth

NEW

Page 34: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Write Without Response would be dropped due to memory pressure

New property will tell your app if more data can be sent

Write Without Response

open class CBPeripheral: CBPeer { open var canSendWriteWithoutResponse: Bool { get } }

public protocol CBPeripheralDelegate: NSObjectProtocol { optional public func peripheralIsReady(toSendWriteWithoutResponse peripheral: CBPeripheral) }

NEW

Page 35: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

•Platform Support

Page 36: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

macOS 10.7 iOS 5

Page 37: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

macOS 10.7 iOS 5 tvOS 9

Page 38: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

macOS 10.7 iOS 5 tvOS 9 watchOS 4

Page 39: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

iOS + macOS

Page 40: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

iOS + macOS

Foreground and background apps

Page 41: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

iOS + macOS

Foreground and background apps

Central and Peripheral

Page 42: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

iOS + macOS

Foreground and background apps

Central and Peripheral

15 ms minimum connection interval

Page 43: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

iOS + macOS

Foreground and background apps

Central and Peripheral

15 ms minimum connection interval

State Preservation and Restoration on iOS

Page 44: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

tvOS

Page 45: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

tvOS

Foreground app only

Page 46: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

tvOS

Foreground app only

Central role only

Page 47: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

tvOS

Foreground app only

Central role only

Limited to 2 simultaneous connections

Page 48: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

tvOS

Foreground app only

Central role only

Limited to 2 simultaneous connections

30 ms minimum connection interval

Page 49: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

tvOS

Foreground app only

Central role only

Limited to 2 simultaneous connections

30 ms minimum connection interval

Peripherals disconnected when app ismoved to the background

Page 50: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

watchOSNEW

Page 51: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

watchOS

Access dictated by system runtime policies

NEW

Page 52: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

watchOS

Access dictated by system runtime policies

Central role only

NEW

Page 53: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

watchOS

Access dictated by system runtime policies

Central role only

Limited to 2 simultaneous connections

NEW

Page 54: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

watchOS

Access dictated by system runtime policies

Central role only

Limited to 2 simultaneous connections

30 ms minimum connection interval

NEW

Page 55: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

watchOS

Access dictated by system runtime policies

Central role only

Limited to 2 simultaneous connections

30 ms minimum connection interval

Peripherals disconnected when app is suspended

NEW

Page 56: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

watchOS

Access dictated by system runtime policies

Central role only

Limited to 2 simultaneous connections

30 ms minimum connection interval

Peripherals disconnected when app is suspended

Supported on Apple Watch Series 2

NEW

Page 57: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

•L2CAP Channels

NEW

Page 58: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

L2CAP Connection Oriented Channels

Bluetooth SIG Protocol underlying all communication

Logical Link Control and Adaptation Protocol

Stream between two devices

Introduced for LE in Bluetooth Core Spec 4.1

Page 59: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

L2CAP Channels

CBCentralManager

CBService

CBCharacteristic

CBCharacteristic

CBCharacteristic

Page 60: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

L2CAP Channels

CBCentralManager

CBService

CBCharacteristic

CBCharacteristic

CBCharacteristic

CBL2CAPChannel CBL2CAPChannel

Page 61: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Open an L2CAP Channel on an existing CBPeripheral connection

Central Side L2CAP

open class CBPeripheral: CBPeer { open func openL2CAPChannel(_ PSM: CBL2CAPPSM) }

public protocol CBPeripheralDelegate: NSObjectProtocol { optional public func peripheral(_ peripheral: CBPeripheral,

didOpen channel: CBL2CAPChannel?, error: Error?) }

Page 62: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

SIG Specified PSM for standardized profiles

Locally assigned PSM for dynamic services

PSM

/*! * @const CBUUIDL2CAppSMCharacteristicString * @discussion The PSM (a little endian uint16_t) of an L2CAP Channel associated with the GATT service * containing this characteristic. Servers can publish this characteristic with the UUID * ABDD3056-28FA-441D-A470-55A75A52553A */public let CBUUIDL2CAppSMCharacteristicString: String

Page 63: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Listen for incoming L2CAP Channels

Peripheral Side L2CAP

open class CBPeripheralManager : CBManager { open func publishL2CAPChannel(withEncryption encryptionRequired: Bool) open func unpublishL2CAPChannel(_ PSM: CBL2CAPPSM) }

public protocol CBPeripheralManagerDelegate : NSObjectProtocol { optional public func peripheralManager(_ peripheral: CBPeripheralManager, didPublishL2CAPChannel PSM: CBL2CAPPSM, error: Error?) }

Page 64: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Opening an L2CAP Channel

CBCentralManager

MyService

MyData

Page 65: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Opening an L2CAP Channel

CBCentralManager

MyService

MyData

peripheral.publishL2CAPChannel(withEncryption: true)

Page 66: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Opening an L2CAP Channel

CBCentralManager

MyService

MyData

optional public func peripheralManager(_ peripheral: CBPeripheralManager, didPublishL2CAPChannel PSM: CBL2CAPPSM, error: Error?)

Page 67: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Opening an L2CAP Channel

CBCentralManager

MyService

L2CAP PSM

MyData

optional public func peripheralManager(_ peripheral: CBPeripheralManager, didPublishL2CAPChannel PSM: CBL2CAPPSM, error: Error?)

L2CAP PSM

Page 68: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Opening an L2CAP Channel

CBCentralManager

MyService

L2CAP PSM

MyData

Page 69: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Opening an L2CAP Channel

CBCentralManager

MyService

L2CAP PSM

MyData

Page 70: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Opening an L2CAP Channel

CBCentralManager

MyService

L2CAP PSM

MyData

peripheral.openL2CAPChannel(PSM)

Page 71: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Opening an L2CAP Channel

CBCentralManager

MyService

L2CAP PSM

MyData

CBL2CAPChannel CBL2CAPChannel

optional public func peripheralManager(_ peripheral: CBPeripheralManager, didOpen channel: CBL2CAPChannel?, error: Error?)

Page 72: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

@available(macOS 10.13, iOS 11.0, *) open class CBL2CAPChannel: NSObject {

open var peer: CBPeer! { get }

open var inputStream: InputStream! { get }

open var outputStream: OutputStream! { get }

open var psm: CBL2CAPPSM { get }

}

Page 73: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Stream events are delivered through NSStream

Stream Events

public protocol StreamDelegate: NSObjectProtocol { optional public func stream(_ aStream: Stream, handle eventCode: Stream.Event) }

public struct Stream.Event: OptionSet { public static var openCompleted: Stream.Event { get } public static var hasBytesAvailable: Stream.Event { get } public static var hasSpaceAvailable: Stream.Event { get } public static var errorOccurred: Stream.Event { get } public static var endEncountered: Stream.Event { get } }

Page 74: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Closing Channels

Channels may be closed due to • Link loss • Central close • Peripheral unpublished • Peripheral object is released

Page 75: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

When Should L2CAP Be Used?

Use GATT where it makes sense

Lowest overhead

Best performance

Best for large data transfers

Great for stream protocols

Page 76: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

•Best Practices

Page 77: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Follow the Bluetooth AccessoryDesign Guidelines for Apple Products

Page 78: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Use Existing Profiles and Services

Page 79: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Why does it take so long to connect?

Page 80: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Time to Discover

Peripheral

Central

Advertisement

Advertising

Scanning

Page 81: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Time to Discover

Peripheral

Central

Advertisement Advertisement Advertisement Advertisement

Advertising

Scanning

ScanScan

Page 82: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Connection Speed

Use the shortest advertising interval possible

Optimize for when users are trying to use your accessory

See the Bluetooth Accessory Design Guidelines for power-efficient advertising intervals

Page 83: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

No need to scan for a peripheral for reconnect

Retrieve the peripheral and directly connect

Reconnecting devices

let identifier = UUID()

let peripherals = central.retrievePeripherals(withIdentifiers: [ identifier ])

central.connect(peripherals[0])

Page 84: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Service Discovery Speed

Battery (16 bit)

Battery Level

MyService (128 bit)

MoreData

OtherData

MyData

Device Information (16 bit)

PnP ID

Software Version

Serial Number

CBService

CBCharacteristic

CBCharacteristic

CBCharacteristic

Page 85: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Service Discovery Speed

Use as few services/characteristics as possible

Battery (16 bit)

Battery Level

MyService (128 bit)

MoreData

OtherData

MyData

Device Information (16 bit)

PnP ID

Software Version

Serial Number

CBService

CBCharacteristic

CBCharacteristic

CBCharacteristic

Page 86: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Service Discovery Speed

Use as few services/characteristics as possible

Battery (16 bit)

Battery Level

MyService (128 bit)

MoreData

OtherData

MyData

Device Information (16 bit)

PnP ID

Software Version

Serial Number

Page 87: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Service Discovery Speed

Use as few services/characteristics as possible

Group services by UUID size

Battery (16 bit)

Battery Level

MyService (128 bit)

MoreData

OtherData

MyData

Device Information (16 bit)

PnP ID

Software Version

Serial Number

Page 88: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Service Discovery Speed

Use as few services/characteristics as possible

Group services by UUID size

Support GATT Caching

Battery (16 bit)

Battery Level

MyService (128 bit)

MoreData

OtherData

MyData

Device Information (16 bit)

PnP ID

Software Version

Serial Number

Page 89: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Service Discovery Speed

Use as few services/characteristics as possible

Group services by UUID size

Support GATT Caching

Use “Service Changed”

Battery (16 bit)

Battery Level

MyService (128 bit)

MoreData

OtherData

MyData

Device Information (16 bit)

PnP ID

Software Version

Serial Number

Page 90: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

New Accessory Recommendations

Use the newest chipset / Bluetooth standard available

4.2 and 5.0 are backward compatible

Follow these best practices

Page 91: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Duy Phan, Bluetooth Engineer

•Getting the Most out of Core Bluetooth

Page 92: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

1MB = 3,240 seconds 2.5 kbps

Page 93: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Protocol Overhead

Controller

L2CAP

ATT

Application

GATT

Controller

L2CAP

ATT

Application

GATT

L2CAP 4 Bytes

Attribute Data20 Bytes

ATT 3 Bytes

Packet

Page 94: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Protocol Overhead

Controller

L2CAP

ATT

Application

GATT

Controller

L2CAP

ATT

Application

GATT

L2CAP 4 Bytes

Attribute Data20 Bytes

ATT 3 Bytes

Packet

Page 95: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Write With Response

Peripheral

Central

Inte

rval

Inte

rval

Inte

rval

Page 96: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Write With Response

Peripheral

Central

Write

Response

Inte

rval

Inte

rval

Inte

rval

Page 97: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Write With Response

Peripheral

Central

Inte

rval

Inte

rval

Inte

rval

Page 98: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Write Without Response

Reliable with Core Bluetooth flow control

Use all available connection events to transmit

Takes advantage of larger Connection Event Length

Page 99: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Write Without ResponseIn

terv

al

Inte

rval

Inte

rval

Page 100: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Write Without Response

Default MTU

37kbps

Inte

rval

Inte

rval

Inte

rval

Page 101: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Write Without Response

Default MTU

37kbps

Inte

rval

Inte

rval

Inte

rval

Page 102: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Write Without Response

Default MTU

Larger MTU

37kbps

Inte

rval

Inte

rval

Inte

rval

48kbps

Page 103: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Apple devices determine the optimal MTU

Accessories should support a large MTU

Use large attributes aligned to MTU

Fitting your data

open class CBPeripheral: CBPeer { open func maximumWriteValueLength(for type: CBCharacteristicWriteType) -> Int }

open class CBCentral: CBPeer { open var maximumUpdateValueLength: Int { get } }

Page 104: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Write Without Response

Default MTU

Larger MTU

Inte

rval

Inte

rval

Inte

rval

37kbps

48kbps

Page 105: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Write Without Response

EDL

Default MTU

Larger MTU

Inte

rval

Inte

rval

Inte

rval

37kbps

48kbps

Page 106: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Write Without Response

EDL

Default MTU

Larger MTU

10x 10x 10x

Inte

rval

Inte

rval

Inte

rval

37kbps

48kbps

135kbps

Page 107: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Extended Data Length

New Feature in Bluetooth 4.2

Much larger packets (251 vs 27 bytes)

Transparent to the application

4x throughput with the same radio time

Available on iPhone 7 and Apple Watch Series 2

Page 108: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

L2CAP Connection Oriented Channels

ATT

Application

GATT

Controller

L2CAP

Controller

L2CAP

ATT

Application

GATT

L2CAP 4 Bytes

Attribute Data247 Bytes

Packet

Page 109: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

L2CAP Connection Oriented Channels

Application

Controller

L2CAP

Controller

L2CAP

Application

L2CAP 4 Bytes

Attribute Data247 Bytes

Packet

197 kbps

Page 110: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Faster Connection Interval

L2CAP + EDL

Inte

rval

Inte

rval

Inte

rval

Page 111: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Faster Connection Interval

L2CAP + EDL

Inte

rval

Inte

rval

Inte

rval

394 kbps

Inte

rval

Inte

rval

Page 112: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Throughput (kbps)

Write With Response

Write Without Response

Packed CE Length

Larger MTU

EDL

L2CAP + EDL

L2CAP + EDL + 15ms Int

0 40 80 120 160 200 240 280 320 360 400

Page 113: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Throughput (kbps)

Write With Response

Write Without Response

Packed CE Length

Larger MTU

EDL

L2CAP + EDL

L2CAP + EDL + 15ms Int

0 40 80 120 160 200 240 280 320 360 400

2.5

Page 114: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Throughput (kbps)

Write With Response

Write Without Response

Packed CE Length

Larger MTU

EDL

L2CAP + EDL

L2CAP + EDL + 15ms Int

0 40 80 120 160 200 240 280 320 360 400

2.5

5.2

Page 115: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Throughput (kbps)

Write With Response

Write Without Response

Packed CE Length

Larger MTU

EDL

L2CAP + EDL

L2CAP + EDL + 15ms Int

0 40 80 120 160 200 240 280 320 360 400

2.5

5.2

37

Page 116: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Throughput (kbps)

Write With Response

Write Without Response

Packed CE Length

Larger MTU

EDL

L2CAP + EDL

L2CAP + EDL + 15ms Int

0 40 80 120 160 200 240 280 320 360 400

2.5

5.2

37

48

Page 117: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Throughput (kbps)

Write With Response

Write Without Response

Packed CE Length

Larger MTU

EDL

L2CAP + EDL

L2CAP + EDL + 15ms Int

0 40 80 120 160 200 240 280 320 360 400

2.5

5.2

37

48

135

Page 118: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Throughput (kbps)

Write With Response

Write Without Response

Packed CE Length

Larger MTU

EDL

L2CAP + EDL

L2CAP + EDL + 15ms Int

0 40 80 120 160 200 240 280 320 360 400

2.5

5.2

37

48

135

197

Page 119: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Throughput (kbps)

Write With Response

Write Without Response

Packed CE Length

Larger MTU

EDL

L2CAP + EDL

L2CAP + EDL + 15ms Int

0 40 80 120 160 200 240 280 320 360 400

2.5

5.2

37

48

135

197

394

Page 120: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Summary

Request a shorter Connection Interval

Take advantage of GATT optimizations

Use L2CAP Channel for large transfers and stream protocols

Update your hardware (4.2 EDL, 5.0) for best performance and battery life

Page 121: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Craig Dooley, Bluetooth Engineer

•Wrap Up

Page 122: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Key Takeaways

Check out State Restoration

Expand your app to tvOS and watchOS

Use L2CAP for stream protocols or large data transfers

Use the newest Bluetooth chipset available

Follow the Bluetooth Accessory Design Guidelines

Page 123: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

More Informationhttps://developer.apple.com/wwdc17/712

Page 124: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Related Sessions

Core Bluetooth 101 WWDC 2012

Core Bluetooth WWDC 2013

Page 125: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed

Labs

Bluetooth Lab Technology Lab J Thur 12:00PM–2:00PM

Bluetooth Lab Technology Lab J Fri 12:00PM–2:00PM

Page 126: •What’s New in Core Bluetooth - Development Videos - … ID Software Version Serial Number CBService CBCharacteristic CBCharacteristic CBCharacteristic Service Discovery Speed