<< Writing an SDK With Core Bluetooth – 17 – Asking QuestionsWriting an SDK With Core Bluetooth – 19 – The Code >>
At this point, the Peripheral is getting the question. Time to answer it.
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:
- The app uses the SDK’s “
sendAnswer(_:)
” method of theITCB_SDK_Device_Central
instance that was sent with the question, to send the answer (as a String). - The
ITCB_SDK_Device_Central
instance calls the Core BluetoothCBPeripheralManager.updateValue(-:, for:, onSubscribedCentrals:)
method to send the new value of the answer Characteristic to the Central. - The Peripheral gets a confirmation callback, using the observer
answerSentToDevice(_:, answer:, toQuestion:)
method, that the answer was sent. - 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 theITCB_SDK_Device_Peripheral
instance that the Central had assigned to the Peripheral. - The device instance will then use the
ITCB_SDK_Central
instance to send thequestionAnsweredByDevice(_:)
observer callback to the app.
In the next entry, we’ll walk through the code that implements this.