-
Notifications
You must be signed in to change notification settings - Fork 375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
init CentralManager with restorationId causes unsupported state #264
Comments
@driveorphone Could you tell me on what device are you trying to do this? I've tested it on my iPhone and it works without a problem. |
@paweljaneczek sorry didn't mention I'm testing it on an iPhone 6s with iOS 11.3.1 |
@driveorphone By saying class TestClass: CBCentralManagerDelegate {
configureCentralManager() {
manager = CBCentralManager(delegate: self, queue: .main, options: [CBCentralManagerOptionRestoreIdentifierKey:"get.myId.centralManagerRestoreKey" as AnyObject])
print("state \(central.state)")
}
centralManagerDidUpdateState(_ central: CBCentralManager) {
print("newState \(central.state)")
}
} |
@paweljaneczek indeed I'm using var manager = CentralManager( queue: .main,
options: [CBCentralManagerOptionRestoreIdentifierKey:"get.myId.centralManagerRestoreKey" as AnyObject],
onWillRestoreCentralManagerState: {
centralManagerRestoredState in
print("RXBT centralManagerRestoredState is \(centralManagerRestoredState)")
// do any stuff here later...
}
) |
At least I could reproduce this issue with CBCentralManager itself: still no idea where it can come from but it means that your lib might not be in cause. Closing that ticket then... And thank you for your time + for this awesome lib! |
For whom it could help, I found that just by forcing unwrapping type of CentralManager at initialization did solve the issue. Although I don't really understand what it involves behind the scene, worth to mention it. This does not work: var manager = CentralManager( queue: .main,
/* etc. etc. */
) This does work: var manager:CentralManager! = CentralManager( queue: .main,
/* etc. etc. */
) |
Hi @paweljaneczek @driveorphone, I am facing the same issue. Even after I dispose the scanning output and restart the scanning, I get |
@aksswami I could note that it happens more often on iPhones <= 6s, and much less often on iPhones >= 7. |
Thanks for suggestions @driveorphone. We don't face this problem when we remove the restoreKey. Can you elaborate on the downside of doing that? I still don't get the complete idea of restoration. As anyway, we do a peripheral scan and connect each time we want to do something with any peripheral. Also, there are not methods or docs explaining the restoration process in RxBluetoothKit. |
@aksswami you need the restoration feature only if you need to ensure a future connexion to your device while your application will be backgrounded and/or terminated by the system. The way it works in a few words is :
|
Thanks @driveorphone. This is really helpful. For my purpose, I don't require restoration as I am only using peripheral when the application is in the foreground. But I would really like to debug this issue. Why are we having this state issue when using restoration key. May post here, in case I have something. Thanks again. |
I don't know if this is still needed but might be helpful for some people: if you use state restoration, you shouldn't have two CBCentralManagers alive with the same restore identifier. When you create the second one, you will receive state This might happen if you have a leak somewhere and the first CBCentralManager doesn't deallocate correctly. |
I'm facing a weird issue (version 5.1.0 of this lib):
When using the CentralManager without any init option, the observeState() observable is well working.
But as soon as I add a restore identifier key, the observeState() observable just sends one (and only one) unsupported state, then no more events even after enabling/disabling Bluetooth (either from control center or Settings).
As soon as I remove the restoreIdentifier options, it works back again nicely...
Is there anything wrong I did, or an issue in the lib? Thanks for the help!
Here is the observe state part that prints everything happening there:
CentralManager initialization without options:
CentralManager initialization with restore options:
The text was updated successfully, but these errors were encountered: