-
Notifications
You must be signed in to change notification settings - Fork 115
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
CentralManager state reported as unsupported if already connected to a peripheral. Errors thrown are sometimes CoreBluetooth errors instead of PeripheralError. #62
Comments
Look at this code. https://github.com/troystribling/BlueCap/blob/master/Examples/CentralManager/CentralManager/ViewController.swift#L113-L178. I do not see how your example works. Where does
I have only seen the
How may peripherals are you connect to? What are the reported errors. |
I do a scan in another class for a list of peripherals which then populates a tableView. Then, after selecting one in the list, I have another class object that gets instantiated for each Peripheral chosen, which is the self.peripheral variable. I start off with I can connect to one peripheral fine, and then I get an Most of the time I get CBError.connectionTimeout, so I just had to include it in the switch case and it seems to handle it fine. I just wasn't sure if it was just leaking through and not being caught by BlueCap, or just being thrown somewhere that isn't capturable. |
Can you send me a link to your app? If you call It is better to just check the state. You should be able to see the CoreBluetooth reset event in the system log. Monitor the log when you run the app and see if you see the event. How many peripherals did you discover? Having a large number of CBPeripherals can also cause a CoreBluetooth crash. |
I can't send you the link, but here's the portions pertaining to it: Scanning and passing array to a delegate:
This is called when selecting a peripheral from a list after a scan.
In these particular cases, only two peripherals were discovered, and only two were attempted to be connected to. |
I am not able to reproduce your problem. I tested this code successfully which calls
I think you are somehow crashing CoreBluetooth by either leaking CBPeripherals or have too many open connections. Did you check the logs for a crash? |
It looks like I had instantiated another central with the same restore identifier key elsewhere and that's why it returned a unsupported state. Sorry for the trouble. I will update my code and see if I can get it working properly. Thanks for your help. |
If I connect to, discover services and characteristics, notify and receive notification updates with a peripheral and I use the same central to attempt to connect and do the same with another peripheral, the state of the CentralManager is unsupported, yet if I forgo the state checking and connect anyway, it works as intended.
I am running this on an iPhone 7 Plus 256GB running iOS 10.3.2 beta 4.
Here is my code for the connection, discovery, etc.:
As for errors being thrown, I have to use CBErrors to catch some of them, like so:
The text was updated successfully, but these errors were encountered: