Class

CBPeripheralManager

CBPeripheralManager objects are used to manage published services within the local peripheral device’s Generic Attribute Profile (GATT) database and to advertise these services to central devices (represented by CBCentral objects). While a service is in the database, it is visible to, and can be accessed by, any connected central. That said, if your app has not specified the bluetooth-peripheral background mode, the contents of its services become disabled when it is in the background or in a suspended state; any remote central trying to access the service’s characteristic value or characteristic descriptors receives an error.

Overview

Before you call CBPeripheralManager methods, the state of the peripheral manager object must be powered on, as indicated by the poweredOn. This state indicates that the peripheral device (your iPhone or iPad, for instance) supports Bluetooth low energy and that its Bluetooth is on and available to use.

Symbols

Initializing a Peripheral Manager

init(delegate: CBPeripheralManagerDelegate?, queue: DispatchQueue?)

Initializes the peripheral manager with a specified delegate and dispatch queue.

init(delegate: CBPeripheralManagerDelegate?, queue: DispatchQueue?, options: [String : Any]? = nil)

Initializes the peripheral manager with specified delegate, dispatch queue, and initialization options.

var delegate: CBPeripheralManagerDelegate?

The delegate object specified to receive peripheral events.

Monitoring the State of a Peripheral Manager

var state: CBPeripheralManagerState

The current state of the peripheral manager.

class func authorizationStatus()

Returns the app’s authorization status for sharing data while in the background state.

Adding and Removing Services

func add(CBMutableService)

Publishes a service and any of its associated characteristics and characteristic descriptors to the local GATT database.

func remove(CBMutableService)

Removes a specified published service from the local GATT database.

func removeAllServices()

Removes all published services from the local GATT database.

Managing Advertising

func startAdvertising([String : Any]?)

Advertises peripheral manager data.

func stopAdvertising()

Stops advertising peripheral manager data.

var isAdvertising: Bool

A Boolean value indicating whether the peripheral is currently advertising data.

Sending Updates of a Characteristic’s Value

func updateValue(Data, for: CBMutableCharacteristic, onSubscribedCentrals: [CBCentral]?)

Sends an updated characteristic value to one or more subscribed centrals, via a notification or indication.

Responding to Read and Write Requests

func respond(to: CBATTRequest, withResult: CBATTError.Code)

Responds to a read or write request from a connected central.

Setting Connection Latency

func setDesiredConnectionLatency(CBPeripheralManagerConnectionLatency, for: CBCentral)

Sets the desired connection latency for an existing connection to a central device.

Constants

CBPeripheralManagerState

Values representing the current state of the peripheral manager.

CBPeripheralManagerConnectionLatency

Values representing the connection latency of the peripheral manager.

CBPeripheralManagerAuthorizationStatus

Values representing the current authorization state of the peripheral manager.

Initializers

Relationships

Inherits From

Conforms To