didReceiveWrite with enormous delay

Hello everybody,


I'm currently trying to build an emulator for BLE hardware we created. I implemented the CBPeripheralManager and its protocol to allow iOS device with iOS 9+ to act like the real hardware.


This all works well despite one thing. In specific characteristics I have a huge delay when I try to write values in them. Specifically the request from the CBPeripheralManagerDelegate is partly delayed up to 10 sec. I tried to investigate the issue but I came to no clear conclusion. It seems like iOS itself is seeming to somehow block the message for some time. Sadly there is very little documentation about the CBPeripheralManager and some pieces seem to be not implemented into the CoreBluetooth framework.


Still I think I make something wrong, but I'm unable to see what it is. I setup a simple project to demonstrate my issue. You can find it on https://bitbucket.org/binux92/hardware-emulator-ios. There you will also find instructions on how to reproduce the issue. The characteristics which have this delay are called "CA Configuration" and "CA Status". The characteristic which reacts immediatly is called "CA Change".


I would be very pleased if someone could try to reproduce my issue and help me fixing it. It might be due to some misconfiguration on my side or it might be a actual CoreBluetooth bug. Then it would be great to know if there's a workaround for it.


Regards

Replies

Any luck with this? I'm in the same exact boat, literally writing an emulator for our custom BLE hardware, and I'm seeing the same exact 10 second (precisely, everytime) delay in didReceiveWrites being called, when I'm watching the debug console of our main app in another Xcode project happily writing over BLE without issue, and not with that delay.


We had found a combination of connection initialization parameters that greatly increased the speed of our BLE communication on our hardware when interacting with an Apple deivce, so I thought there might be a similar issue on my peripheral app side, and I tried setting the connection latency via the setDesiredConnectionLatency(.low, for: central) function on the peripheral manager, specifically on the callback for a characteristic subscription, but that seems to make no difference.

It's probably too late for the original askers, but for anyone new, please remember to call peripheral.respond(to:withResult:) in the didReceiveWrite requests and didReceiveRead request delegate functions. That seems to solve the issue.

See also: https://developer.apple.com/documentation/corebluetooth/cbperipheralmanager/1393293-respond