I am writing an app that needs to write a byte value to a CBPeripheral
using iOS CoreBluetooth
. I am able to read values, and the write is successful and triggers the didWriteValueFor
delegate like it should. Basically, it does work, BUT, it takes a long time (about 3 seconds and reports of over 10). When I test the write process in another app (nRF Connect), the write is almost instantaneous. Here's the code I am using to write to the Characteristic:
func setConfigurationValue(_ i:UInt8){
guard peripheral != nil, configurationStateCharacteristic != nil else { return }
var vint:UInt8 = i
let intData = Data(bytes: &vint, count: MemoryLayout<UInt8>.size)
isWriting = true
peripheral?.writeValue(intData, for: configurationStateCharacteristic!, type: CBCharacteristicWriteType.withResponse)
// Notify any views that they should show a progress overlay
NotificationName.showProgressOverlay.post(userInfo: ["message":"Device configuring".localized], object: self)
}
Note, that peripheral
is a stored reference to the CBPeripheral
object, and configurationStateCharacteristic
is a reference to the CBCharacteristic
I am writing to. This code does work, but what is causing the peripheral BLE device to take so long in writing the data and sending a response?
Any ideas?