Bluetooth Logo

Writing an SDK With Core Bluetooth – 18 – The Answer

This entry is part 22 of 24 in the series Writing an SDK With Core Bluetooth

At this point, the Peripheral is getting the question. Time to answer it.

The Timeline for an Answer

The user of the Peripheral Mode device now has a question that was asked by the Central Mode device displayed. They select an answer, or simply hit the “SEND A RANDOM ANSWER” button. This will initiate the process illustrated in the timeline above.

Here’s what is happening:

  1. The app uses the SDK’s “sendAnswer(_:)” method of the ITCB_SDK_Device_Central instance that was sent with the question, to send the answer (as a String).
  2. The ITCB_SDK_Device_Central instance calls the Core Bluetooth CBPeripheralManager.updateValue(-:, for:, onSubscribedCentrals:) method to send the new value of the answer Characteristic to the Central.
  3. The Peripheral gets a confirmation callback, using the observer answerSentToDevice(_:, answer:, toQuestion:) method, that the answer was sent.
  4. On the Central end of things, the CBPeripheral that was associated with the Peripheral device is notified that a Characteristic value has a proposed update, and uses the CBPeripheralDelegate.peripheral(_:, didUpdateValueFor:, error:) method of the ITCB_SDK_Device_Peripheral instance that the Central had assigned to the Peripheral.
  5. The device instance will then use the ITCB_SDK_Central instance to send the questionAnsweredByDevice(_:)observer callback to the app.

In the next entry, we’ll walk through the code that implements this.