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

PDF
Bluetooth Over-The-Air Firmware Update
PPTX
You are not_hiding_from_me_.net
PPTX
PHP Continuous Data Processing
PDF
DevOps - Infrastructure as Code by Andre Marcelo-Tanner
PPTX
Architecting for Continuous Delivery
PPTX
Immutable Server generation: The new App Deployment
PDF
What if a video dev redesigned a serverless API?
PDF
Deploying Plone on AWS
Bluetooth Over-The-Air Firmware Update
You are not_hiding_from_me_.net
PHP Continuous Data Processing
DevOps - Infrastructure as Code by Andre Marcelo-Tanner
Architecting for Continuous Delivery
Immutable Server generation: The new App Deployment
What if a video dev redesigned a serverless API?
Deploying Plone on AWS

What's hot (20)

PPTX
Architecting for continuous delivery (33rd Degree)
PDF
Two Years, Zero servers: Lessons learned from running a startup 100% on Serve...
PDF
Jenkins Docker
PDF
Game of Codes: the Battle for CI
PDF
Hello elixir (and otp)
PDF
How to setup jenkins
PDF
Security in serverless world
PDF
DevOps with Serverless
PDF
Serverless in production, an experience report
PDF
There is No Server: Immutable Infrastructure and Serverless Architecture
PDF
AtlasCamp 2015 Docker continuous integration training
PDF
mykola marzhan - jenkins on aws spot instance
PPTX
Tech trends 2018 2019
PDF
fmcsadmin 1.0.0
PPT
State of Puppet 2013 - Puppet Camp DC
KEY
Selenium Grid
PDF
Ansible Case Studies
PDF
Docker, Continuous Integration, and You
PPTX
Running eZ Platform on Kubernetes (presented by Björn Dieding at eZ Conferenc...
PDF
Ansible
Architecting for continuous delivery (33rd Degree)
Two Years, Zero servers: Lessons learned from running a startup 100% on Serve...
Jenkins Docker
Game of Codes: the Battle for CI
Hello elixir (and otp)
How to setup jenkins
Security in serverless world
DevOps with Serverless
Serverless in production, an experience report
There is No Server: Immutable Infrastructure and Serverless Architecture
AtlasCamp 2015 Docker continuous integration training
mykola marzhan - jenkins on aws spot instance
Tech trends 2018 2019
fmcsadmin 1.0.0
State of Puppet 2013 - Puppet Camp DC
Selenium Grid
Ansible Case Studies
Docker, Continuous Integration, and You
Running eZ Platform on Kubernetes (presented by Björn Dieding at eZ Conferenc...
Ansible
Ad

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

PDF
BTLE (Bluetooth Low Energy) and CoreBluetooth
PDF
Where should I run my code? Serverless, Containers, Virtual Machines and more
PPTX
Gatekeeper: API gateway
PDF
Why do we even have Kubernetes?
PDF
Lunar Way and the Cloud Native "stack"
PDF
Cloud Native Data Warehouses - Intro to ClickHouse on Kubernetes-2021-07.pdf
PDF
Using eBPF to Measure the k8s Cluster Health
PDF
Introduction to Kubernetes with demo
PPTX
Scaling Docker Containers using Kubernetes and Azure Container Service
PPT
Kubernetes for Cloud-Native Environments
PPTX
Keynote #Tech - Google : aperçu de la gestion des services distribués chez Go...
PDF
Deploy Application on Kubernetes
PDF
Developer-Friendly CI / CD for Kubernetes
PDF
Kubernetes - Sailing a Sea of Containers
PDF
Data Warehouses in Kubernetes Visualized: the ClickHouse Kubernetes Operator UI
PDF
Ignacy Kowalczyk
PDF
Introduction to Kubernetes and GKE
PDF
Core Bluetooth and BLE 101
PDF
Communication Amongst Microservices: Kubernetes, Istio, and Spring Cloud with...
PDF
'DOCKER' & CLOUD: ENABLERS For DEVOPS
BTLE (Bluetooth Low Energy) and CoreBluetooth
Where should I run my code? Serverless, Containers, Virtual Machines and more
Gatekeeper: API gateway
Why do we even have Kubernetes?
Lunar Way and the Cloud Native "stack"
Cloud Native Data Warehouses - Intro to ClickHouse on Kubernetes-2021-07.pdf
Using eBPF to Measure the k8s Cluster Health
Introduction to Kubernetes with demo
Scaling Docker Containers using Kubernetes and Azure Container Service
Kubernetes for Cloud-Native Environments
Keynote #Tech - Google : aperçu de la gestion des services distribués chez Go...
Deploy Application on Kubernetes
Developer-Friendly CI / CD for Kubernetes
Kubernetes - Sailing a Sea of Containers
Data Warehouses in Kubernetes Visualized: the ClickHouse Kubernetes Operator UI
Ignacy Kowalczyk
Introduction to Kubernetes and GKE
Core Bluetooth and BLE 101
Communication Amongst Microservices: Kubernetes, Istio, and Spring Cloud with...
'DOCKER' & CLOUD: ENABLERS For DEVOPS
Ad

Recently uploaded (20)

PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
Introduction to Artificial Intelligence
PPTX
history of c programming in notes for students .pptx
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Nekopoi APK 2025 free lastest update
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PPTX
ISO 45001 Occupational Health and Safety Management System
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Understanding Forklifts - TECH EHS Solution
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPT
Introduction Database Management System for Course Database
Odoo POS Development Services by CandidRoot Solutions
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
CHAPTER 2 - PM Management and IT Context
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
How to Migrate SBCGlobal Email to Yahoo Easily
Introduction to Artificial Intelligence
history of c programming in notes for students .pptx
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Nekopoi APK 2025 free lastest update
Softaken Excel to vCard Converter Software.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
2025 Textile ERP Trends: SAP, Odoo & Oracle
Internet Downloader Manager (IDM) Crack 6.42 Build 41
ISO 45001 Occupational Health and Safety Management System
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Understanding Forklifts - TECH EHS Solution
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Odoo Companies in India – Driving Business Transformation.pdf
Introduction Database Management System for Course Database

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