Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Fun With Core Bluetooth

Fun With Core Bluetooth

Bluetooth is everywhere! Using iOS, find bluetooth devices and read their information.

Patrick Weigel

April 12, 2018
Tweet

More Decks by Patrick Weigel

Other Decks in Programming

Transcript

  1. Cocoa Coders 2018-04-12 Core Bluetooth CocoaCoders Introductions 7:00 Show and

    Tell Presentation Informal Socialization 7:10 7:30 8:45
  2. 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
  3. Minimal Concepts Nouns • Central • Peripheral • Services •

    Characteristics • Values Verbs • Discover • Connect C ore Bluetooth Cocoa Coders 2018-04-12 Core Bluetooth
  4. 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
  5. 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
  6. 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) }
  7. 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
  8. Ready for Demo C ore Bluetooth Cocoa Coders 2018-04-12 Core

    Bluetooth • Recap • Concepts • Code https://speakerdeck.com/patrick462/fun-with-core-bluetooth
  9. 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
  10. 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
  11. Completed Demo C ore Bluetooth Cocoa Coders 2018-04-12 Core Bluetooth

    • Recap • Concepts • Code • Demo https://speakerdeck.com/patrick462/fun-with-core-bluetooth
  12. Minimal Concepts Nouns • Central • Peripheral • Services •

    Characteristics • Values Verbs • Discover • Connect C ore Bluetooth Cocoa Coders 2018-04-12 Core Bluetooth
  13. 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
  14. 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
  15. 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