Dunfey · Hotel WWDC as data, est. 1983
Front desk everything
Years
Topics

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 ↗

Transcript all transcripts

Code shown on screen · 2 snippets

Listen for alerts swift · at 3:41 ↗
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 swift · at 9:15 ↗
func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
    central.scanForPeripherals(withServices: [myCustomUUID])
}

Resources