I'm developing an App that needs, in certan scenarios, to be connected to a bluetooth Peripheral indefinitely.
Before I go on with my question, I want to confirm that:
- I'm initializing my
CBCoreBluetoothManager
indidFinishLaunchingWithOptions:
. - I have
bluetooth-central
background capabilities enabled. - I am using State Preservation and Restoration by having the Manager being initialized with a key, and implementing
willRestoreState
: - Before my problem happens, I have a successful connection with my Peripheral, I get its service (I'm only looking for one) and its characteristic (again I'm only looking for one) for which I do set
setNotifyValue:
toYES
. Aditionally, while both in the Foreground, and the background, I get callbacks ondidUpdateValueForCharacteristic:
everytime the characteristic's value updates. - I am simulating the "suspended state" with
kill(getpid(), SIGKILL)
(I have also tested it by just putting the app in the background, and letting it sit for 1 hour+) - When I say suspended, I mean the actual
Suspended
state. Which I believe every app eventually gets there, after being put in the background for an amount of time.
The problem that I am having, is with getting callbacks on didUpdateValueForCharacteristic:
when the app is suspended. Again I do get callbacks if the app is in the background, but not when it is suspended. Meaning, the app does not get woken up by a value update on the characteristic.
The funny thing is that while I have the app in suspended mode, and I walk out of the Peripheral range to disconnect, and then back in range to re-connect, the app will be woken up, because it will try to restore (it calls willRestoreState:) and for a brief time, will listen to any characteristic values updates.
To sum up, while my app is in the suspended state, and in range of the Peripheral, didUpdateValueForCharacteristic does not get called, meaning the app does not get woken up, by what I am 100% sure, is a characteristic value update. It would however, wake up the app, if I walk out of the Peripheral's range, and back in, because I am supporting State Preservation and Restoration.
From Apple's documentation:
The system wakes up your app when any of the CBCentralManagerDelegate or CBPeripheralDelegate delegate methods are invoked, allowing your app to handle important central role events, such as when a connection is established or torn down, when a peripheral sends updated characteristic values, and when a central manager’s state changes.
It seems that I should be getting those updates, has anybody ever had a problem like this?
Any help is appreciated!
Thanks in advance