Guides and Sample Code

Developer

Playground Book Format Reference

PlaygroundBluetoothCentralManagerDelegate

A delegate you use to respond to peripheral discovery and manage the lifecycle of connections.

Instance Methods

centralManagerStateDidChange(_:)

Tells the delegate that the state of the central manager has changed.

Required. Default implementation provided.

Declaration

  • func centralManagerStateDidChange(_ centralManager: PlaygroundBluetoothCentralManager)

Parameters

centralManager

The central manager providing this information.

centralManager(_:didDiscover:withAdvertisementData:rssi:)

Tells the delegate that a peripheral has been discovered during scanning.

Required. Default implementation provided.

Declaration

  • func centralManager(_ centralManager: PlaygroundBluetoothCentralManager, didDiscover peripheral: CBPeripheral, withAdvertisementData advertisementData: [String: Any]?, rssi: Double)

Parameters

centralManager

The central manager providing this information.

peripheral

The newly-discovered peripheral.

advertisementData

A dictionary containing any advertisement data that the peripheral provides.

rssi

The current received signal strength indicator of the peripheral in decibels.

centralManager(_:willConnectTo:)

Tells the delegate that the central manager is about to attempt to establish a connection with a peripheral.

Required. Default implementation provided.

Declaration

  • func centralManager(_ centralManager: PlaygroundBluetoothCentralManager, willConnectTo peripheral: CBPeripheral)

Parameters

centralManager

The central manager attempting the new connection.

peripheral

The peripheral that the central manager is attempting to connect to.

centralManager(_:didConnectTo:)

Tells the delegate that the central manager established a connection with a peripheral.

Required. Default implementation provided.

Declaration

  • func centralManager(_ centralManager: PlaygroundBluetoothCentralManager, didConnectTo peripheral: CBPeripheral)

Parameters

centralManager

The central manager that made the new connection.

peripheral

The newly connected peripheral.

centralManager(_:didFailToConnectTo:error:)

Tells the delegate that the central manager failed to establish a connection with a peripheral.

Required. Default implementation provided.

Declaration

  • func centralManager(_ centralManager: PlaygroundBluetoothCentralManager, didFailToConnectTo peripheral: CBPeripheral, error: Error?)

Parameters

centralManager

The central manager that failed to make the new connection.

peripheral

The peripheral that the central manager couldn’t connect to.

error

An error which describes the reason for the connection failure.

centralManager(_:didDisconnectFrom:error:)

Tells the delegate that the central manager disconnected from a peripheral.

Required. Default implementation provided.

Declaration

  • func centralManager(_ centralManager: PlaygroundBluetoothCentralManager, didDisconnectFrom peripheral: CBPeripheral, error: Error?)

Parameters

centralManager

The central manager that disconnected from a peripheral.

peripheral

The peripheral that the central manager disconnected from.

error

An error which, if present, describes the reason for the connection failure. The absence of an error indicates that the disconnection was requested via the manager’s disconnect(from:) method.