How does CBPeripheralManager know that it is connected or disconnected by a central device in Core Bluetooth?

At the central end, a CBPeripheral delegate will be called when connecting or disconnecting. But how does CBPeripheralManager know that it is connected or disconnected by the central device? In addition, is it possible for the peripheral device to reject the connection request from the central device?

+6
source share
1 answer

You do not receive special notification when the central one connects to the peripheral service provided by your application. You can infer a connection from the following CBPeripheralManagerDelegate called methods -

  • didSubscribeToCharacteristic
  • didReceiveReadRequest
  • didReceiveWriteRequest

If you received a subscription through didSubscribeToCharacteristic , you can conclude that you disconnect when you receive a corresponding call to didUnsubscribeFromCharacteristic . If the central device does not use subscriptions, then you do not have indications that they are disabled - you simply will not receive more read / write requests.

You cannot refuse a connection to the central one. You can set the encryption requirement for one or more of your characteristics. This then initiates the pin-based pairing process when the central first tries to read / write / notify about this property.

You can also implement some authentication procedure where the central part must answer the call / write a password for the characteristic, etc., before answering these central other read / write requests.

+5
source

Source: https://habr.com/ru/post/977080/


All Articles