Reputation: 1107
I have the following code in the peripheral manager delegate
func peripheralManager(_ peripheral: CBPeripheralManager, didReceiveWrite requests: [CBATTRequest]) {
print ("received write request")
for request in requests {
if request.characteristic.uuid.isEqual(self.primaChar.uuid) {
// extract data from write request
// TODO: validate data
let str = String(data: request.value!, encoding: .utf8)!
print ("received:", str)
peripheralManager.respond(to: request, withResult: .success)
} else {
print ("Unknown write request")
}
}
}
After the response call
peripheralManager.respond(to: request, withResult: .success)
didWrite isn't called at the central side
func peripheral(_ peripheral: CBPeripheral, didWriteValueFor descriptor: CBDescriptor, error: Error?) {
#if DEBUG
CLog.debug ("Did write value for \(descriptor.characteristic)")
#endif
}
I need to initiate multiple write requests but need to know if the previous write was successful, before sending the next write request.
Both the devices are paired.
Why is central manager's didWriteValueFor() not getting called?
Upvotes: 0
Views: 1217
Reputation: 1107
Using didWriteValueForCharscteristic() fixed the problem as suggested by @Paulw11 in the comments. Thanks Paul.
Upvotes: 0