SlideShare a Scribd company logo
YmsCoreBluetooth
A block-based API for Core Bluetooth
YmsCoreBluetooth
Core Bluetooth
▸ Bluetooth 4.0 Low Energy (BLE) API
▸ Released 2012 (iOS 5, macOS 10.10)
▸ Delegate-based
▸ Many updates, but very few API changes
▸ Established BLE as the standard Personal Area Network
(PAN) for mobile
Gadgets!
TI SensorTag
Mid-2013
YmsCoreBluetooth
TI SensorTag
▸ IR Temperature Sensor
▸ Humidity Sensor
▸ Gyroscope
▸ Accelerometer
▸ Magnetometer
▸ Barometric Pressure Sensor
▸ Temperature Sensor
▸ Battery/voltage Sensor
▸ Push Buttons
BLE!
Core Bluetooth!
Using the Core Bluetooth
API felt kinda awkward.
YmsCoreBluetooth
Programming the SensorTag with Core Bluetooth
▸ Delegation pattern for CBCentralManager and CBPeripheral
was clumsy to use
▸ 8 sensors = 8 services
▸ Each service had at least two characteristics
▸ Control, Data
▸ A lot of state to keep track of in different places
In 2013, ObjC blocks were
a thing. Why not use them
here?
History
YmsCoreBluetooth
▸ Inspired by AFNetworking
▸ Use Obj-C block to process response from a BLE request
▸ Captures state
▸ In-line syntax describes control flow in “one place”
▸ Released late 2013 on GitHub
▸ https://github.com/kickingvegas/YmsCoreBluetooth
Design Goals
YmsCoreBluetooth Design Goals
▸ Get a BLE app up and running fast
▸ Be ready to use in a production app
▸ Use SensorTag as reference model to sanity check above
Design Goals
API Design
▸ Wrapper classes around each Core Bluetooth class
▸ YMSCBCentralManager
▸ YMSCBPeripheral
▸ YMSCBService
▸ YMSCBCharacteristic
▸ YMSCBDescriptor
▸ Subclass off appropriate YMSCB* to personalize
YMSCBCentralManager
CBCentralManager
Design Goals
Hierarchical Object Operation
▸ Core Bluetooth API designed operations in terms of 

sender sends message to receiver with matching delegate
response
▸ CBCentralManager connects to CBPeripheral
▸ CBPeripheral discovers its CBServices
▸ CBPeripheral discovers the CBCharacteristics for a CBService
▸ CBPeripheral writes to CBCharacteristic
▸ High cognitive load
Design Goals
Hierarchical Object Operation
▸ YmsCoreBluetooth API designed operations in terms of 

sending a command to an object
▸ [YMSCBPeripheral connectWithOptions:withBlock:]
▸ [YMSCBPeripheral discoverServices:withBlock:]
▸ [YMSCBService discoverCharacteristics:withBlock:]
▸ [YMSCBCharacteristic writeValue:withBlock:]
Where are we now
YmsCoreBluetooth in the Wild
▸ First released on GitHub late 2013
▸ Last update 2015
▸ As of 4/12/17
▸ 498 stars
▸ 128 forks
Coming Real Soon
YmsCoreBluetooth Updates Coming!
▸ Improved YMSCBPeripheral collection handling
▸ Improved BLE scanning API
▸ Improved YMSCBCharacteristic subscription API
▸ Dependency Injection Everywhere
▸ Testability
▸ Decouple from Core Bluetooth objects
▸ Obj-C Nullability & Generics
▸ May 2017
github.com/

kickingvegas/

YmsCoreBluetooth
twitter: cy_choi
Deep Core Bluetooth
Learning stuff the hard way
HMM… THAT’S FUNNY, IT
WORKS FOR ME.
Any developer writing a Core Bluetooth app
Deep Core Bluetooth
Learning 1: Your app
doesn’t have direct access
to the hardware
CBCentralManager
CBPeripheral
App A
BLE Peripheral
CBCentralManager
CBPeripheral
App A
BT Server
BLE Peripheral
BLE HW
CBCentralManager
CBPeripheral
CBCentralManager
CBPeripheral
App A
BT Server
BLE Peripheral
BLE HW
CBCentralManager
CBPeripheral
CBCentralManager
CBPeripheral
App A
CBCentralManager
CBPeripheral
CBCentralManager
CBPeripheral
App B
BT Server
BLE Peripheral
BLE HW
Deep Core Bluetooth
Learning 1: Your app doesn’t have direct access to the hardware
▸ CBPeripheral connection is a logical connection
▸ BT Server manages the physical connection to an actual BLE
peripheral
▸ Core Bluetooth state restoration works because of this
▸ Core Bluetooth background execution is decoupled from the
app state
Learning 2: Unpaired
CBPeripheral identifiers
are cached values
BLE Peripheral BT Server App
advertising MAC: 1235
didDiscoverPeripheral: FRED
advertising MAC: 1235
didDiscoverPeripheral: FRED
Map MAC to Identifier
Map MAC to Identifier
Map MAC to Identifier Full
advertising MAC: 1235
didDiscoverPeripheral: JANE
Deep Core Bluetooth
Learning 2: Unpaired CBPeripheral Identifiers are Cached
▸ There is a fixed size table for mapping MAC addresses to
CBPeripheral identifiers in BT Server
▸ When this table is full, an identifier will be invalidated
▸ To test an identifier, you must call 

[CBCentralManager retrievePeripheralsWithIdentifiers:]
▸ iOS 10 made this table really big
Learning 3: If BT Server resets
when your backgrounded BLE app
is not running, you won’t hear of it.
BLE Peripheral BT Server App
connectPeripheral:
connectPeripheral:
didConnectPeripheral: didConnectPeripheral:
Resets!
App terminated 

in background
centralManagerDidUpdateState:
Deep Core Bluetooth
Learning 3: If BT Server resets when your background app is not running, you won’t hear of it
▸ Core Bluetooth background execution is reliant on BT Server
always running perfectly
▸ If BT Server resets and your app that supports background
execution is not running, you will not receive the
centralManagerDidUpdateState: message
Learning 4: BLE state
restoration is a lot of work
Text
Learning 4: BLE state restoration is a lot of work
▸ Restore ServiceUUIDs that were scanned for
▸ You must restore your scan handler
▸ Restore Peripherals that central manager was trying to connect to or had
already connected to
▸ You must restore your connection and discovery handlers
▸ Restore Characteristics the central manager was subscribed to
▸ You must restore your notification handlers
▸ Run-time state you keep for a connected peripheral must be restored too!
Deep Core Bluetooth
Core Bluetooth Abstracts BLE
▸ Core Bluetooth is an abstraction API on top of the BLE
protocol
▸ Mimics BLE link-layer transactions
▸ Exercises only a sub-set of BLE protocol
▸ Your central never has direct communication with your
peripheral
We ❤ Core Bluetooth

More Related Content

What's hot (20)

PPTX
Architecting for continuous delivery (33rd Degree)
Axel Fontaine
 
PDF
Two Years, Zero servers: Lessons learned from running a startup 100% on Serve...
Cloud Native Day Tel Aviv
 
PDF
Jenkins Docker
Alex Soto
 
PDF
Game of Codes: the Battle for CI
Atlassian
 
PDF
Hello elixir (and otp)
Abel Muíño
 
PDF
How to setup jenkins
linuxdady
 
PDF
Security in serverless world
Yan Cui
 
PDF
DevOps with Serverless
Yan Cui
 
PDF
Serverless in production, an experience report
Yan Cui
 
PDF
There is No Server: Immutable Infrastructure and Serverless Architecture
Sonatype
 
PDF
AtlasCamp 2015 Docker continuous integration training
Steve Smith
 
PDF
mykola marzhan - jenkins on aws spot instance
Dariia Seimova
 
PPTX
Tech trends 2018 2019
Johan Norm
 
PDF
fmcsadmin 1.0.0
Atsushi Matsuo
 
PPT
State of Puppet 2013 - Puppet Camp DC
Puppet
 
KEY
Selenium Grid
nirvdrum
 
PDF
Ansible Case Studies
Greg DeKoenigsberg
 
PDF
Docker, Continuous Integration, and You
Atlassian
 
PPTX
Running eZ Platform on Kubernetes (presented by Björn Dieding at eZ Conferenc...
eZ Systems
 
PDF
Ansible
Rahul Bajaj
 
Architecting for continuous delivery (33rd Degree)
Axel Fontaine
 
Two Years, Zero servers: Lessons learned from running a startup 100% on Serve...
Cloud Native Day Tel Aviv
 
Jenkins Docker
Alex Soto
 
Game of Codes: the Battle for CI
Atlassian
 
Hello elixir (and otp)
Abel Muíño
 
How to setup jenkins
linuxdady
 
Security in serverless world
Yan Cui
 
DevOps with Serverless
Yan Cui
 
Serverless in production, an experience report
Yan Cui
 
There is No Server: Immutable Infrastructure and Serverless Architecture
Sonatype
 
AtlasCamp 2015 Docker continuous integration training
Steve Smith
 
mykola marzhan - jenkins on aws spot instance
Dariia Seimova
 
Tech trends 2018 2019
Johan Norm
 
fmcsadmin 1.0.0
Atsushi Matsuo
 
State of Puppet 2013 - Puppet Camp DC
Puppet
 
Selenium Grid
nirvdrum
 
Ansible Case Studies
Greg DeKoenigsberg
 
Docker, Continuous Integration, and You
Atlassian
 
Running eZ Platform on Kubernetes (presented by Björn Dieding at eZ Conferenc...
eZ Systems
 
Ansible
Rahul Bajaj
 

Similar to SV iOS Meetup Slides: YmsCoreBluetooth and Deep Core Bluetooth (20)

PDF
BTLE (Bluetooth Low Energy) and CoreBluetooth
Zach Dennis
 
PDF
How Hot is My Coffee? Sensors, iOS and Core Bluetooth
Evan Stone
 
PDF
Core Bluetooth and BLE 101
Li Lin
 
PDF
Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016
Shuichi Tsutsumi
 
PDF
How Hot is My Coffee? Sensors, Core Bluetooth, and Swift!
Evan Stone
 
PDF
Practical Core Bluetooth in IoT & Wearable projects @ UIKonf 2016
Shuichi Tsutsumi
 
PDF
Alberto Guarino "When iPhones and Wearables Dance the Bluetooth Dance: Lesson...
IT Event
 
PDF
Building iOS apps using "Bluetooth Low Energy"
Shuichi Tsutsumi
 
PDF
A Brief Introduction to Bluetooth Low Energy (BLE) on iOS
Matt Whitlock
 
PPTX
Introduction to Bluetooth Low Energy
yeokm1
 
PPTX
Modbus using Coreblue Bluetooth for iOS to connect to a hardware sensor
Azukisoft Pte Ltd
 
PDF
Demystifying Android's Bluetooth Low Energy at MCE^3 Conf
Pawel Urban
 
PDF
MCE^3 - Dariusz Seweryn, Paweł Urban - Demystifying Android's Bluetooth Low ...
PROIDEA
 
PPT
Ble boise codecamp
Chip Keyes
 
PDF
IntenetOfThingsWithBLEAndBeacons
Vivek Jain
 
PDF
Bluetooth Low Energy Unveiled
G Gindele
 
PDF
挖掘低耗電藍芽的寶藏
evan3rd
 
PDF
Core Bluetooth on iOS
storywithoutend
 
PPTX
Reverse engineering
La_Lu
 
PDF
Real time sensing with bluetooth smart
Tue Haste Andersen
 
BTLE (Bluetooth Low Energy) and CoreBluetooth
Zach Dennis
 
How Hot is My Coffee? Sensors, iOS and Core Bluetooth
Evan Stone
 
Core Bluetooth and BLE 101
Li Lin
 
Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016
Shuichi Tsutsumi
 
How Hot is My Coffee? Sensors, Core Bluetooth, and Swift!
Evan Stone
 
Practical Core Bluetooth in IoT & Wearable projects @ UIKonf 2016
Shuichi Tsutsumi
 
Alberto Guarino "When iPhones and Wearables Dance the Bluetooth Dance: Lesson...
IT Event
 
Building iOS apps using "Bluetooth Low Energy"
Shuichi Tsutsumi
 
A Brief Introduction to Bluetooth Low Energy (BLE) on iOS
Matt Whitlock
 
Introduction to Bluetooth Low Energy
yeokm1
 
Modbus using Coreblue Bluetooth for iOS to connect to a hardware sensor
Azukisoft Pte Ltd
 
Demystifying Android's Bluetooth Low Energy at MCE^3 Conf
Pawel Urban
 
MCE^3 - Dariusz Seweryn, Paweł Urban - Demystifying Android's Bluetooth Low ...
PROIDEA
 
Ble boise codecamp
Chip Keyes
 
IntenetOfThingsWithBLEAndBeacons
Vivek Jain
 
Bluetooth Low Energy Unveiled
G Gindele
 
挖掘低耗電藍芽的寶藏
evan3rd
 
Core Bluetooth on iOS
storywithoutend
 
Reverse engineering
La_Lu
 
Real time sensing with bluetooth smart
Tue Haste Andersen
 
Ad

Recently uploaded (20)

PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PPTX
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
PPTX
Engineering the Java Web Application (MVC)
abhishekoza1981
 
PPTX
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
PDF
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
PDF
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
PDF
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PPTX
The Role of a PHP Development Company in Modern Web Development
SEO Company for School in Delhi NCR
 
DOCX
Import Data Form Excel to Tally Services
Tally xperts
 
PDF
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
PPTX
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PDF
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
PDF
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
PPTX
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
PPTX
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
Engineering the Java Web Application (MVC)
abhishekoza1981
 
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
The Role of a PHP Development Company in Modern Web Development
SEO Company for School in Delhi NCR
 
Import Data Form Excel to Tally Services
Tally xperts
 
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
Ad

SV iOS Meetup Slides: YmsCoreBluetooth and Deep Core Bluetooth

  • 2. YmsCoreBluetooth Core Bluetooth ▸ Bluetooth 4.0 Low Energy (BLE) API ▸ Released 2012 (iOS 5, macOS 10.10) ▸ Delegate-based ▸ Many updates, but very few API changes ▸ Established BLE as the standard Personal Area Network (PAN) for mobile
  • 5. YmsCoreBluetooth TI SensorTag ▸ IR Temperature Sensor ▸ Humidity Sensor ▸ Gyroscope ▸ Accelerometer ▸ Magnetometer ▸ Barometric Pressure Sensor ▸ Temperature Sensor ▸ Battery/voltage Sensor ▸ Push Buttons BLE! Core Bluetooth!
  • 6. Using the Core Bluetooth API felt kinda awkward.
  • 7. YmsCoreBluetooth Programming the SensorTag with Core Bluetooth ▸ Delegation pattern for CBCentralManager and CBPeripheral was clumsy to use ▸ 8 sensors = 8 services ▸ Each service had at least two characteristics ▸ Control, Data ▸ A lot of state to keep track of in different places
  • 8. In 2013, ObjC blocks were a thing. Why not use them here?
  • 9. History YmsCoreBluetooth ▸ Inspired by AFNetworking ▸ Use Obj-C block to process response from a BLE request ▸ Captures state ▸ In-line syntax describes control flow in “one place” ▸ Released late 2013 on GitHub ▸ https://github.com/kickingvegas/YmsCoreBluetooth
  • 10. Design Goals YmsCoreBluetooth Design Goals ▸ Get a BLE app up and running fast ▸ Be ready to use in a production app ▸ Use SensorTag as reference model to sanity check above
  • 11. Design Goals API Design ▸ Wrapper classes around each Core Bluetooth class ▸ YMSCBCentralManager ▸ YMSCBPeripheral ▸ YMSCBService ▸ YMSCBCharacteristic ▸ YMSCBDescriptor ▸ Subclass off appropriate YMSCB* to personalize YMSCBCentralManager CBCentralManager
  • 12. Design Goals Hierarchical Object Operation ▸ Core Bluetooth API designed operations in terms of 
 sender sends message to receiver with matching delegate response ▸ CBCentralManager connects to CBPeripheral ▸ CBPeripheral discovers its CBServices ▸ CBPeripheral discovers the CBCharacteristics for a CBService ▸ CBPeripheral writes to CBCharacteristic ▸ High cognitive load
  • 13. Design Goals Hierarchical Object Operation ▸ YmsCoreBluetooth API designed operations in terms of 
 sending a command to an object ▸ [YMSCBPeripheral connectWithOptions:withBlock:] ▸ [YMSCBPeripheral discoverServices:withBlock:] ▸ [YMSCBService discoverCharacteristics:withBlock:] ▸ [YMSCBCharacteristic writeValue:withBlock:]
  • 14. Where are we now YmsCoreBluetooth in the Wild ▸ First released on GitHub late 2013 ▸ Last update 2015 ▸ As of 4/12/17 ▸ 498 stars ▸ 128 forks
  • 15. Coming Real Soon YmsCoreBluetooth Updates Coming! ▸ Improved YMSCBPeripheral collection handling ▸ Improved BLE scanning API ▸ Improved YMSCBCharacteristic subscription API ▸ Dependency Injection Everywhere ▸ Testability ▸ Decouple from Core Bluetooth objects ▸ Obj-C Nullability & Generics ▸ May 2017
  • 17. Deep Core Bluetooth Learning stuff the hard way
  • 18. HMM… THAT’S FUNNY, IT WORKS FOR ME. Any developer writing a Core Bluetooth app Deep Core Bluetooth
  • 19. Learning 1: Your app doesn’t have direct access to the hardware
  • 24. Deep Core Bluetooth Learning 1: Your app doesn’t have direct access to the hardware ▸ CBPeripheral connection is a logical connection ▸ BT Server manages the physical connection to an actual BLE peripheral ▸ Core Bluetooth state restoration works because of this ▸ Core Bluetooth background execution is decoupled from the app state
  • 25. Learning 2: Unpaired CBPeripheral identifiers are cached values
  • 26. BLE Peripheral BT Server App advertising MAC: 1235 didDiscoverPeripheral: FRED advertising MAC: 1235 didDiscoverPeripheral: FRED Map MAC to Identifier Map MAC to Identifier Map MAC to Identifier Full advertising MAC: 1235 didDiscoverPeripheral: JANE
  • 27. Deep Core Bluetooth Learning 2: Unpaired CBPeripheral Identifiers are Cached ▸ There is a fixed size table for mapping MAC addresses to CBPeripheral identifiers in BT Server ▸ When this table is full, an identifier will be invalidated ▸ To test an identifier, you must call 
 [CBCentralManager retrievePeripheralsWithIdentifiers:] ▸ iOS 10 made this table really big
  • 28. Learning 3: If BT Server resets when your backgrounded BLE app is not running, you won’t hear of it.
  • 29. BLE Peripheral BT Server App connectPeripheral: connectPeripheral: didConnectPeripheral: didConnectPeripheral: Resets! App terminated 
 in background centralManagerDidUpdateState:
  • 30. Deep Core Bluetooth Learning 3: If BT Server resets when your background app is not running, you won’t hear of it ▸ Core Bluetooth background execution is reliant on BT Server always running perfectly ▸ If BT Server resets and your app that supports background execution is not running, you will not receive the centralManagerDidUpdateState: message
  • 31. Learning 4: BLE state restoration is a lot of work
  • 32. Text Learning 4: BLE state restoration is a lot of work ▸ Restore ServiceUUIDs that were scanned for ▸ You must restore your scan handler ▸ Restore Peripherals that central manager was trying to connect to or had already connected to ▸ You must restore your connection and discovery handlers ▸ Restore Characteristics the central manager was subscribed to ▸ You must restore your notification handlers ▸ Run-time state you keep for a connected peripheral must be restored too!
  • 33. Deep Core Bluetooth Core Bluetooth Abstracts BLE ▸ Core Bluetooth is an abstraction API on top of the BLE protocol ▸ Mimics BLE link-layer transactions ▸ Exercises only a sub-set of BLE protocol ▸ Your central never has direct communication with your peripheral
  • 34. We ❤ Core Bluetooth