What is the correct way to respond to the peripheral manager: didReceiveWriteRequests?

What is the correct way to respond to the peripheral manager: didReceiveWriteRequests?

The header documentation states that:

"For each call to this method, responseToRequestWithResult should be called exactly once."

In didReceiveWriteRequests, several write requests are passed using NSArray.

If all write requests are successfully processed, we just randomly select the request from the list and use it as an argument for responseToRequestWithResult, since the responseToRequestWithResult method takes only one CBATTRequest argument, and not the CBATTRequests list that came with didReceiveWriteRequests?

I expected the symmetric response method to take a list of queries as an argument.

-Chip Keyes

+4
source share
1 answer

From Apple documentation: Here

Processing write requests from a connected central element is also simple. When the connected central server sends a request to write the value of one or more of your characteristics, the peripheral manager calls the peripheralManager: didReceiveWriteRequests: method of its delegate object. This time, the delegate method delivers the requests to you in the form of an array containing one or more CBATTRequest objects, each of which represents a write request. After you make sure that the write request can be executed, you can write the value of the characteristics, for example:

myCharacteristic.value = request.value; 

Although the above example does not demonstrate this, be sure to consider the query biasing property when writing the value of your attribute.

Just as you respond to a read request, call the responseToRequest: withResult: method exactly once, each time the peripheralManager: didReceiveWriteRequests: delegate method is called. However, the first parameter responseToRequest: withResult: method expects a single CBATTRequest object, even if you may have received an array containing more than one of them from the peripheralManager: didReceiveWriteRequests: delegate method. You must pass the first array request, for example:

 [myPeripheralManager respondToRequest:[requests objectAtIndex:0] withResult:CBATTErrorSuccess]; 
+4
source

All Articles