2022 Health & FitnessSystem Services
WWDC22 · 14 min · Health & Fitness / System Services
Get timely alerts from Bluetooth devices on watchOS
Find out how Bluetooth devices can send timely and relevant alerts to Apple Watch. We’ll show you how to take advantage of periodic data in complications, explore background peripheral discovery, and help you learn how to use characteristic monitoring in watchOS. We’ll also share best practices and design guidance for creating a great Bluetooth accessory.
Watch at developer.apple.com ↗Code shown on screen · 2 snippets
Listen for alerts
func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {
peripheral.setNotifyValue(true, for: characteristic)
}
func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) {
if let newData = characteristic.value {
// Post a local notification.
}
} Discover peripherals
func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
central.scanForPeripherals(withServices: [myCustomUUID])
} Resources
Related sessions
-
11 min