Share
Embed
Fun With Core Bluetooth
Bluetooth is everywhere! Using iOS, find bluetooth devices and read their information.
Patrick Weigel
April 12, 2018
Transcript
17 slides
-
Cocoa Coders 2018-04-12 Core Bluetooth CocoaCoders Introductions 7:00 Show and
Tell Presentation Informal Socialization 7:10 7:30 8:45 -
Fun With Core Bluetooth Minimal Concepts Minimal Code Minimal Demo
Cocoa Coders 2018-04-12 Core Bluetooth https://speakerdeck.com/patrick462/fun-with-core-bluetooth -
Minimal Concepts Nouns • Central • Peripheral • Services •
Characteristics • Values Verbs • Discover • Connect C ore Bluetooth Cocoa Coders 2018-04-12 Core Bluetooth -
Minimal Code (Nouns) Code • CBCentralManager • CBPeripheral • peripheral.services
• services. characteristics • It’s complicated C ore Bluetooth Cocoa Coders 2018-04-12 Core Bluetooth Nouns • Central • Peripheral • Services • Characteristics • Values -
Minimal Code (Verbs) func blahblah1 didConnect peripherals { . .
. selectedPeripheral.discoverServices } func blahblah2 didDiscover services { . . . do things with services } C ore Bluetooth Cocoa Coders 2018-04-12 Core Bluetooth https://speakerdeck.com/patrick462/fun-with-core-bluetooth -
Minimal Code (Verbs) func viewDidLoad { . . . centralManager
= CBCentralManager } func blahblah1 centralManagerDidUpdateState { . . . manager.scanForPeripherals(blah blah) } func blahblah2 didDiscover peripherals { . . . manager.connect(selectedPeripheral) } func blahblah3 didConnect peripheral { . . . selectedPeripheral.discoverServices } C ore Bluetooth Cocoa Coders 2018-04-12 Core Bluetooth func blahblah4 didDiscover services { . . . selectedService.discoverCharacteristics } func blahblah5 didDiscover characteristics { . . . peripheral.readValue(for: selectedCharactistic) } func blahblah6 didUpdateValueFor characteristic { . . . peripheral.readValue(for: selectedCharactistic) } -
Minimal Code (Verbs) centralManager = CBCentralManager centralManagerDidUpdateState { manager.scanForPeripherals(blah blah)
didDiscover peripherals { manager.connect(selectedPeripheral) didConnect peripheral { selectedPeripheral.discoverServices didDiscover services { selectedService.discoverCharacteristics didDiscover characteristics { peripheral.readValue(for: selectedCharactistic) didUpdateValueFor characteristic { peripheral.readValue(for: selectedCharactistic) C ore Bluetooth Cocoa Coders 2018-04-12 Core Bluetooth https://speakerdeck.com/patrick462/fun-with-core-bluetooth -
Ready for Demo C ore Bluetooth Cocoa Coders 2018-04-12 Core
Bluetooth • Recap • Concepts • Code https://speakerdeck.com/patrick462/fun-with-core-bluetooth -
Minimal Demo C ore Bluetooth Cocoa Coders 2018-04-12 Core Bluetooth
• You Can Do This: • 7 Concepts • ≈80 Lines of Code https://speakerdeck.com/patrick462/fun-with-core-bluetooth -
Minimal Demo 1. New Project 2. Run / Test /
Commit 3. Add in a Noun 4. Repeat steps 2 - 3 C ore Bluetooth Cocoa Coders 2018-04-12 Core Bluetooth https://speakerdeck.com/patrick462/fun-with-core-bluetooth -
Completed Demo C ore Bluetooth Cocoa Coders 2018-04-12 Core Bluetooth
• Recap • Concepts • Code • Demo https://speakerdeck.com/patrick462/fun-with-core-bluetooth -
Minimal Concepts Nouns • Central • Peripheral • Services •
Characteristics • Values Verbs • Discover • Connect C ore Bluetooth Cocoa Coders 2018-04-12 Core Bluetooth -
Minimal Code (Verbs) centralManager = CBCentralManager centralManagerDidUpdateState { manager.scanForPeripherals(blah blah)
didDiscover peripherals { manager.connect(selectedPeripheral) didConnect peripheral { selectedPeripheral.discoverServices didDiscover services { selectedService.discoverCharacteristics didDiscover characteristics { peripheral.readValue(for: selectedCharactistic) didUpdateValueFor characteristic { peripheral.readValue(for: selectedCharactistic) C ore Bluetooth Cocoa Coders 2018-04-12 Core Bluetooth https://speakerdeck.com/patrick462/fun-with-core-bluetooth -
Secret Codes 1. Services https://www.bluetooth.com/specifications/gatt/services 2. Characteristics https://www.bluetooth.com/specifications/gatt/characteristics 3. Slides
https://speakerdeck.com/patrick462/fun-with-core-bluetooth C ore Bluetooth Cocoa Coders 2018-04-12 Core Bluetooth -
Expanded Horizons Any Bluetooth devices out there? Do it on
your machine Look at all the peripherals Work with the secret codes Set up a UI C ore Bluetooth Cocoa Coders 2018-04-12 Core Bluetooth