BLE failing to connect after period when iPhone on charge

. I have an App that has been working reliably on older iPhones but fails on newer devices running iOS 12.


The App links to a device using BLE. The device priodically connects, exchanges data then disconnects, In the didDisconnectPeripheral method I tidy up then attempt to reconnect using connectPeripheral. Several minutes later, when the device advertises on BLE the magic of iOS automatically wakes up the App an re-establishes the connection. This has worked relaibly for years but recently users have reported that the connection dies and this MAY be after a period when the phone is on charge.


My guess is that the connectPeripheral request has been lost by iOS and so I never get the callback.


Does anyone have any ideas?

Replies

The problem still persists in 12.0.1. After further analysis it appears that the BLE connection fails at around 03:00 (UK time) only when the charger is connected, irrespective of when the charger was connected. How weird is that?

It is possible that your app is being terminated during some periodic maintenance cycle.


Do you have Bluetooth State Preservation/Restoration implemented in your app? That should restore your app state after such an event.


Bluetooth State Restoration is an opt-in feature explained more in detail here: https://developer.apple.com/library/archive/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/CoreBluetoothBackgroundProcessingForIOSApps/PerformingTasksWhileYourAppIsInTheBackground.html#//apple_ref/doc/uid/TP40013257-CH7-SW5

Thanks Gualtier


I will give this a go. Problem is it takes several days of testing to check. I will reply with the outcome


Bill


UPDATE:


Its been an interesting journey but I'm pleased to say the problem has gone away but I'm not sure why. My old development machine expired so I had to buy a new MacBook. After updating to the latest iOS I could get the latest XCode. This threw up a few build problems which I fixed. I also spotted that the entry in my .plist for Always On Location which I sorted.I already had the Bluetooth State Restoration enabled as suggested by Gualtier.

Anyway has been working for 2 days now so I think the problem has gone away.