jordanebelanger / SwiftyBluetooth

Closures based APIs for CoreBluetooth
MIT License
209 stars 66 forks source link

Peripheral disconnect recognition #38

Closed quanguyen closed 3 years ago

quanguyen commented 5 years ago

Hi,

How should I detect a peripheral disconnected from the master?

Thanks,

komaxx commented 4 years ago

Same issue here: How can I monitor an already established connection?

jordanebelanger commented 4 years ago

Same issue here: How can I monitor an already established connection?

Hi @komaxx, sorry to hear you're having issues, I've been getting overloaded with work, notably server side Swift stuff and haven't had much time to work on this library.

Do you know of any specific CoreBluetooth hook/notification that does what you need in this case and if so could you share a link to the documentation so I can take a look?

If it's not too hard, you may even want to consider doing a PR for it and I will gladly merge it.

sirowain commented 3 years ago

Any updates on this request? I'm also interested.

jordanebelanger commented 3 years ago

@sirowain https://github.com/jordanebelanger/SwiftyBluetooth/releases/tag/2.2.0

sirowain commented 3 years ago

This is not always working, the method returns before calling the postCentralEvent if you don't have any disconnectRequest for the uuid. If you are trying to detect an unexpected peripheral disconnect you'll miss it.

let uuid = peripheral.identifier
guard let request = disconnectRequests[uuid] else {
    return
}
...
postCentralEvent(Central.CentralCBPeripheralDisconnected, userInfo: userInfo)
jordanebelanger commented 3 years ago

@sirowain Fixed in 2.2.1