Centrals can make requests to read a given characteristic's value and Core Bluetooth facilitates the communication to handle the reading. When necessary, the request is passed to the code in the app to handle the request. This includes setting the value in the request and making the call to send it back.
- [Instructor] As we mentioned,…the point of Bluetooth communication…is to read and write data to and from the peripheral.…So now let's look at how to handle…the read requests on the peripheral.…When the central wants a value from a characteristic,…it calls the read value function.…To process that in our peripheral…we have to implement the CBPeripheralManagerDelegate…and handle the didReceiveRead request.…All we have to do is set the value on the request…and then call respond on the peripheral,…and it'll send it back to the central.…
So let's look at our peripheral code…and handle the didReceiveRead request.…On line 31 I'm going to start writing…the didReceiveRead request.…And on line 32 I'm going to remove the code placeholder,…and all I need to do is on the request…type request and set the value to our property…of myVal.…Once that's set in the request,…all I have to do is respond…using the periperhal.respond function.…
That takes the request that was passed in,…the one that we set the value on,…so I'll set that as the to parameter.…
- Bluetooth Low Energy (BLE) basics
- Core Bluetooth key classes
- Scanning for peripherals
- Discovering services and characteristics
- Writing to a characteristic
- Reconnecting to peripherals
- Apps as peripherals
Skill Level Intermediate
1. BLE Basics
2. Scanning, Connecting, and Discovering
3. Writing to a Characteristic
Adding additional features10m 43s
4. An App as a Peripheral
Next steps1m 7s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.