Fix already connected pheriperal after restoration #235
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #206:
Summary of Problem:
In case of device already being connected during restoration phase in
CBCentralManagerDelegate.centralManager(_ central: CBCentralManager, willRestoreState dict: [String: Any])Bluejay assign connected device toconnectedPeripheral. It breaks further logic as Bluejay didn't start connection explicitly yetCBCentralManagerDelegate.centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral)will be called along the road, which leads to precondition fatal error due to lack ofconnectingPeripheral.Proposed Solution:
I assume that while Bluejay have already
connectedPeripheralit is enough to fill missing gap by assigning it toconnectingPeripheral. In addition i'm checking current queue task to not break further processing.As i'm not familiar with the codebase very well i tried to patch the problem with as less as possible changes, but i can imagine that's not perfect and can lead to some unknown to me side effects, so really appreciate any feedback to this PR.
In next week i will probably do more tests around this patch so maybe sth else will came up;)