Hi Zach,
thank you for your interest in the problem. Please read my explanations below.
Cheers, Andreas
If you look at the console log for your device does it show anything interesting (like BTServer constantly crashing)?
No, no constant crashes. Does this occur in the app after it's been running a while (e.g. does your app constant disconnect, then reconnect later, then disconnect, then reconnect)? Or, does this occur intermittently when launching the app?
Yes. It always works at first. But the peripheral goes in and out of range frequently.
Sometimes it is triggered when the peripheral drops connection due to authentication failure (in our protocol). In that case the App gets the predicted disconnect error: 2014-04-25 10:41:07:686 MyApp[460:5f07] Error Domain=CBErrorDomain Code=7 "The specified device has disconnected from us." UserInfo=0x17e775d0 {NSLocalizedDescription=The specified device has disconnected from us.} But then trying to reconnect after that fails with the issue at hand.
The last time (when I gathered the logs for my previous mail) I have triggered it by taking out the battery of the peripheral and putting it back in repeatedly until the connects started failing. This time around I am trying and trying and it does not want to fail... I have definitely turned Bluetooth on and off and reset the device as I have updated it to iOS 7.1.1. Edit to that: After some time of trying and connecting another peripheral to the device I have managed to get it off balance. It took seven attempts of connecting before it actually succeeded. It is not an infinite reconnect cycle, but it probably could become one after a while of persistent tries.
It seems that it does not occur to "fresh" peripherals. By "fresh" I mean the peripherals that have not yet been connected after the BT and/or device restart. So if one peripheral ran into the reconnection bug cycle, that does not mean the other will.
I believe there is a bug with the bluetooth stack where a iOS device will inconveniently start having issues connecting to a BTLE device if they frequently connect/disconnect/reconnect/etc without stopping/starting bluetooth on the phone or even restarting it. I haven't seen this often but I have seen it.
There is another piece to the story (now when you mentioned the "frequent connect/disconnect/reconnect/etc without stopping/starting bluetooth on the phone or even restarting it" bug). One thing about iOS BT implementation was: if you issue a -connectPeripheral: request the OS will connect the peripheral when it sees it even after weeks since the request. The reality: Yes it does, but it can take up to 5 minutes of being in the range of the peripheral before it does. Which is a major disability.
To get around that I have done the following: Having a timer which periodically canceled the connection request with -cancelPeripheralConnection: and then reissued the -connectPeripheral: request. That works a lot better, but it could be involved with the same bug. Edit to that: Again after some time the issue appeared regardless of the above workaround (I have disabled it a couple of days ago for the purpose of this testing).
|