Should I fulfill all CBATTRequests to write to characteristics or just the first one in the array?

107 views Asked by At

When I receive a

- (void)peripheralManager:(CBPeripheralManager *)peripheral didReceiveWriteRequests:(NSArray *)requests

it's unclear whether or not I'm supposed to fill all the requests but only respond to the first one with a success, or if I'm only supposed to fulfill the first write request and respond to the first one with a success.

When I receive the delegate method, I first follow Apple's note which states

Treat multiple requests as you would a single request—if any individual request cannot be fulfilled, you should not fulfill any of them. Instead, call the respondToRequest:withResult: method immediately and provide a result that indicates the cause of the failure.

By doing

// TODO: doesn't yet take into account offset (request.offset > characteristic.value.length)
for (CBATTRequest *r in requests) {
    if ([validIds indexOfObject:[r.characteristic.UUID UUIDString]] == NSNotFound) {
        NSLog(@"Cannot fulfill write request: %@", r);
        [self.manager respondToRequest:requests[0] withResult:CBATTErrorWriteNotPermitted];
        return;
    }
}

But then, once I'm passed this, and know I can fulfill all of the requests, it's unclear whether or not I'm supposed to actually iterate through all of the requests and write values for characteristics for each one and then when I'm done only respond to the first request, or if I should just fulfill the first request and respond with a success?

0

There are 0 answers