Hope some input will be introduced here.
In my current iOS project, I am using CoreBluetooth with fast. The application has the ability to communicate using CoreBluetooth in the background, which basically works, sort of. The peripheral device requires an active connection to the iOS device to work as expected. Whenever a connection breaks, the peripheral device stops its current action. This also happens when the application closes due to memory pressure. In this case, the peripheral device should not stop working, so the problem. To solve this problem, I followed the basic bluetooth programming guide for apples to implement a state save and restore mode, which basically says:
- Initialize CentralManager using the recovery identifier. Delegate = himself.
- Implement the delegate method willRestoreState. NSLog something
- Run checkOptions for the special key. NSLog is something.
I force iOS to close the application when it is in the background using this common project: BackgroundKill . Of course, the application no longer works in debug mode, so I added some NSLog instructions at important points to look for in the deviceβs console. The good news: the connection is no longer canceled when the application is terminated, iOS now acts as expected to support the connection, so the peripheral device will not stop working. Hit! There is no communication between central and peripheral during this time, with the exception of the battery service to which the application is subscribed. The only reason for an active connection is to prevent the peripheral device from working.
When you restart the application manually, none of the specified NSLogs appears. The willRestoreState delegator is never called, and startOptions is zero. I tried to use the "DISPATCH_QUEUE_CONCURRENT" queue instead of nil when creating an instance of CentralManager. No effect.
How should I use a saved connection when I restart the application? Why did the willRestoreState delegate never call? Am I missing something? Is it mandatory to receive data during the background / forced shutdown of the system in order to use state saving and recovery?
Thanks for the help.:)
source share