We are now ready to have the Central Mode ask a question to one of its Magic 8-Balls.
After we are done with this step, we will be able to run an instance of the app as a Central (on a Mac, iPhone/iPad/iPod, Watch or TV), and an instance of the app as a Peripheral (on a Mac or iPhone/iPad/iPod).
The Central will discover the Peripheral, and display its name in the list. The user will then be able to select the Peripheral, and “ask it a question.”
The Peripheral device will almost immediately display the question.
WHAT HAPPENS WHEN WE ASK

As you can see, this is a lot less involved than discovering the device.
- The Central app uses the
ITCB_Device_Peripheral_Protocolprotocol interface provided by the Central SDK to send the question, as a simple String, using thesendQuestion(_:)method. - The
ITCB_SDK_Device_Peripheral(the actual instance that was accessed by the protocol) finds the Question Characteristic, then uses its associatedCBPeripheralinstance to request a write of that Characteristic from Core Bluetooth. - The Central app is also
ITCB_Observer_Central_Protocol-conformant, so it will receive aquestionAskedOfDevice(_:)callback, to indicate that the question was successfully asked, and displays the question in the log. - Core Bluetooth communicates with Core Bluetooth on the Peripheral device to transmit the write request over to the Peripheral.
- The
ITCB_SDK_PeripheralSDK instance on the Peripheral is aCBPeripheralManagerDelegate, so it receives aCBPeripheralManagerDelegate.peripheralManager(_:, didReceiveWrite:)call from its instance ofCBPeripheralManager. - The Peripheral app is
ITCB_Observer_Peripheral_Protocol-conformant, so it receives aquestionAskedByDevice(_:, question:)call, and displays the question to the user.
Now that we know the question, let’s find the answer…