-
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.
Ressources
Vidéos connexes
WWDC21
-
Rechercher dans cette vidéo…
-
-
3:41 - 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. } } -
9:15 - Discover peripherals
func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) { central.scanForPeripherals(withServices: [myCustomUUID]) }
-