Lock in $30 Savings on PRO—Offer Ends Soon! ⏳

be ready for WATCH — Core Bluetooth 101

be ready for WATCH — Core Bluetooth 101

Blitz Talk I gave at #NSSpain. I would love to give it as a long talk (in Spanish, English, French or German) if you invite me to your conference!

Manu Carrasco Molina

September 19, 2014
Tweet

More Decks by Manu Carrasco Molina

Other Decks in Programming

Transcript

  1. How to be cooler than W ATCH? NOTE TO SELF:

    Presenter Display showing notes and TIME?!
  2. How to be as cool as W ATCH? Core Bluetooth

    in 5 minutes @stuffmc Pomcast.biz
  3. Core Bluetooth Since iOS 5 and OS X 10.7 Yet

    another Universal API Since iPhone 4S and iPad 3 Let’s hope it works on THE watch…
  4. Discover Peripherals Phone looking for Watch central = CBCentralManager(delegate: self,

    queue: nil) func centralManagerDidUpdateState(central: CBCentralManager!) { if central.state == .PoweredOn { central?.scanForPeripheralsWithServices(nil, options: nil) } } func centralManager(central: CBCentralManager!, 
 didDiscoverPeripheral peripheral: CBPeripheral!, 
 advertisementData: [NSObject : AnyObject]!, RSSI: NSNumber!) { central.connectPeripheral(peripheral, options: nil) central.stopScan() } Heart Rate Monitor
  5. Discover Services developer.bluetooth.org/Pages/default.aspx func centralManager(central: CBCentralManager!, 
 didConnectPeripheral peripheral: CBPeripheral!)

    { peripheral.delegate = self peripheral.discoverServices(nil) } func peripheral(peripheral: CBPeripheral!, didDiscoverServices error: NSError!) { for service in peripheral.services { peripheral.discoverCharacteristics(nil, forService: service as CBService) } } Heart Rate Measurement Body Sensor Location
  6. Discover Characteristics developer.bluetooth.org func peripheral(peripheral: CBPeripheral!, didDiscoverCharacteristicsForService service: CBService!, error:

    NSError!) { for char in service.characteristics { peripheral.writeValue(data, 
 forCharacteristic: char, type: .WithoutResponse) // e.g. “Turn LED ON” (sending 0x1) peripheral.readValueForCharacteristic(characteristic: char) // e.g. Body Sensor Location peripheral.setNotifyValue(true, forCharacteristic: char) // e.g. Heart Rate Measurement } } func peripheral(peripheral: CBPeripheral!, 
 didUpdateValueForCharacteristic characteristic: CBCharacteristic!, 
 error: NSError!) { }