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

Conquering CoreBluetooth, a Survival Guide

Conquering CoreBluetooth, a Survival Guide

Dan will dive into how Square Cash utilizes CoreBluetooth to allow their customers to send money to people who are nearby without exchanging a phone number, email address, or username, and without the recipient having to take their phone out of their pocket.

By Dan Federman https://www.linkedin.com/in/dsfed

Powered by http://xebia.com

B94d88549eaca9755b9346a0383b41bb?s=128

do{iOS} conference

November 09, 2015
Tweet

Transcript

  1. Conquering CoreBluetooth A Survival Guide Dan Federman – @TheFederman

  2. Why BLE?

  3. Run Sharing App • Username • Current Heart Rate •

    Average Heart Rate • Distance • Elevation Gain • Average Speed
  4. Peripheral

  5. Services Heart Rate Run Peripheral Username

  6. Heart Rate Current Heart Rate Average Heart Rate Peripheral

  7. Current Heart Rate Average Heart Rate Characteristics Peripheral

  8. Run Distance Elevation Gain Average Speed Peripheral

  9. Current Heart Rate Average Heart Rate Characteristics Distance Elevation Gain

    Average Speed Peripheral Username
  10. Peripheral – Setup [[CBPeripheralManager alloc] initWithDelegate:queue:options:] peripheralManagerDidUpdateState: addService: startAdvertising:

  11. Peripheral – Setup [[CBPeripheralManager alloc] initWithDelegate:queue:options:] CBPeripheralManagerOptionRestoreIdentifierKey CBPeripheralManagerOptionShowPowerAlertKey

  12. Peripheral – Setup [[CBPeripheralManager alloc] initWithDelegate:queue:options:] peripheralManagerDidUpdateState: addService: startAdvertising:

  13. Peripheral – Setup addService: [[CBMutableService alloc] initWithType:primary:] service.characteristics = @[

    characteristic1, … ]
  14. Peripheral – Setup addService: [[CBMutableService alloc] initWithType:primary:] service.characteristics = @[

    characteristic1, … ] [[CBCharacteristic alloc] initWithType: properties: value: permissions:
  15. Peripheral – Setup [[CBPeripheralManager alloc] initWithDelegate:queue:options:] peripheralManagerDidUpdateState: addService: startAdvertising:

  16. Peripheral – Setup startAdvertising: CBAdvertisementDataServiceUUIDsKey

  17. Peripheral – Sending Data peripheralManager:didReceiveReadRequest: respondToRequest:withResult: request.characteristic request.offset request.value CBATTErrorSuccess

    CBATTErrorAttributeNotFound CBATTErrorInvalidOffset
  18. Peripheral – Sending Data request.value = abcdefghijklmnopqrstuvwxyz request.offset == 0

    request.value = klmnopqrstuvwxyz request.offset == 10 request.value = uvwxyz request.offset == 20
  19. Peripheral – Restoration peripheralManager:willRestoreState:

  20. Central

  21. Central – Setup [[CBCentralManager alloc] initWithDelegate:queue:options:] centralManagerDidUpdateState: scanForPeripheralsWithServices:options:

  22. BLE Advertising Packet Preamble (1 byte) Packet Type (4 bytes)

    Checksum (3 bytes) Header Payload 16 bytes 6 - 37 bytes
  23. Central – Reading Data centralManager:didDiscoverPeripheral:advertisementData:RSSI: centralManager:didConnectPeripheral:error: peripheral:didDiscoverServices: peripheral:didDiscoverCharacteristicsForService:error: peripheral:didUpdateValueForCharacteristic:error:

  24. Central – Reading Data centralManager:didDiscoverPeripheral:advertisementData:RSSI: Store peripheral connectPeripheral:options:

  25. Central – Reading Data centralManager:didDiscoverPeripheral:advertisementData:RSSI: centralManager:didConnectPeripheral:error: peripheral:didDiscoverServices: peripheral:didDiscoverCharacteristicsForService:error: peripheral:didUpdateValueForCharacteristic:error:

  26. Central – Reading Data centralManager:didConnectPeripheral:error: setDelegate: discoverServices:

  27. Central – Reading Data centralManager:didDiscoverPeripheral:advertisementData:RSSI: centralManager:didConnectPeripheral:error: peripheral:didDiscoverServices: peripheral:didDiscoverCharacteristicsForService:error: peripheral:didUpdateValueForCharacteristic:error:

  28. Central – Reading Data peripheral:didDiscoverServices: discoverCharacteristics:forService:

  29. Central – Reading Data centralManager:didDiscoverPeripheral:advertisementData:RSSI: centralManager:didConnectPeripheral:error: peripheral:didDiscoverServices: peripheral:didDiscoverCharacteristicsForService:error: peripheral:didUpdateValueForCharacteristic:error:

  30. Central – Reading Data peripheral:didDiscoverCharacteristicsForService:error: readValueForCharacteristic:

  31. Central – Reading Data centralManager:didDiscoverPeripheral:advertisementData:RSSI: centralManager:didConnectPeripheral:error: peripheral:didDiscoverServices: peripheral:didDiscoverCharacteristicsForService:error: peripheral:didUpdateValueForCharacteristic:error:

  32. Central – Reading Data peripheral:didUpdateValueForCharacteristic:error: characteristic.value disconnectPeripheral:

  33. Central – Updating Data

  34. iOS Support 7 8 9

  35. iOS Support 7 8 9

  36. iOS Support 7 8 9

  37. Open Source Spring 2016

  38. Open Source github.com/square/aardvark github.com/square/valet