Jeff Kelley
Jeff Kelley

Reputation: 19071

iOS Peripheral Not Receiving Write Requests after Power Toggle

I have an iOS app that is set up as a peripheral with a CBPeripheralManager and a service with several characteristics. I’m trying to achieve reconnection after the user opens Control Center and toggles Bluetooth off and on. It looks like my service resumes advertising correctly, but I am not ever getting any write request callbacks. I’m expecting ‑peripheralManager:didReceiveWriteRequests: to be called, but it never happens once Bluetooth is turned back on.

Is there anything special we need to do in this case? According to the CBPeripheralManager documentation, we only need to explicitly restart advertisement if the peripheral state goes below PoweredOff. I’m seeing it go to PoweredOff, then PoweredOn, and if I query it, ‑isAdvertising returns YES, and adding the service crashes with an exception because the service is already added.

Upvotes: 1

Views: 84

Answers (1)

p2pkit
p2pkit

Reputation: 1215

In order for the write request to be received you need to first establish a connection to a peripheral, and then write to it.

Could it be that after the bluetooth is reset you are not re-establishing the connection?

Upvotes: 0

Related Questions