Class

CBPeripheral​Manager

CBPeripheral​Manager 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 CBPeripheral​Manager methods, the state of the peripheral manager object must be powered on, as indicated by the powered​On. 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:​ CBPeripheral​Manager​Delegate?, queue:​ Dispatch​Queue?)

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

init(delegate:​ CBPeripheral​Manager​Delegate?, queue:​ Dispatch​Queue?, options:​ [String :​ Any]? = nil)

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

var delegate:​ CBPeripheral​Manager​Delegate?

The delegate object specified to receive peripheral events.

Monitoring the State of a Peripheral Manager

var state:​ CBPeripheral​Manager​State

The current state of the peripheral manager.

class func authorization​Status()

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

Adding and Removing Services

func add(CBMutable​Service)

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

func remove(CBMutable​Service)

Removes a specified published service from the local GATT database.

func remove​All​Services()

Removes all published services from the local GATT database.

Managing Advertising

func start​Advertising([String :​ Any]?)

Advertises peripheral manager data.

func stop​Advertising()

Stops advertising peripheral manager data.

var is​Advertising:​ Bool

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

Sending Updates of a Characteristic’s Value

func update​Value(Data, for:​ CBMutable​Characteristic, on​Subscribed​Centrals:​ [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, with​Result:​ CBATTError.Code)

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

Setting Connection Latency

func set​Desired​Connection​Latency(CBPeripheral​Manager​Connection​Latency, for:​ CBCentral)

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

Constants

CBPeripheral​Manager​State

Values representing the current state of the peripheral manager.

CBPeripheral​Manager​Connection​Latency

Values representing the connection latency of the peripheral manager.

CBPeripheral​Manager​Authorization​Status

Values representing the current authorization state of the peripheral manager.

Initializers

Relationships

Inherits From