Peripheral
public class Peripheral : NSObject
An interface to the Bluetooth peripheral.
-
The UUID of the peripheral.
Declaration
Swift
public var uuid: PeripheralIdentifier { get }
-
Returns the name of the peripheral. If name is not available, return the uuid string.
Declaration
Swift
public var name: String { get }
-
Requests the current RSSI value from the peripheral, and the value is returned via the
RSSIObserver
delegation.Declaration
Swift
public func readRSSI()
-
Register a RSSI observer that can receive the RSSI value when
readRSSI
is called.Declaration
Swift
public func register(observer: RSSIObserver)
-
Unregister a RSSI observer.
Declaration
Swift
public func unregister(observer: RSSIObserver)
-
Read from a specified characteristic.
Declaration
Swift
public func read<R: Receivable>(from characteristicIdentifier: CharacteristicIdentifier, completion: @escaping (ReadResult<R>) -> Void)
-
Write to a specified characteristic.
Declaration
Swift
public func write<S: Sendable>(to characteristicIdentifier: CharacteristicIdentifier, value: S, type: CBCharacteristicWriteType = .withResponse, completion: @escaping (WriteResult) -> Void)
-
Checks whether Bluejay is currently listening to the specified charactersitic.
Declaration
Swift
public func isListening(to characteristicIdentifier: CharacteristicIdentifier) -> Bool
-
Listen for notifications on a specified characterstic.
Declaration
Swift
public func listen<R: Receivable>(to characteristicIdentifier: CharacteristicIdentifier, completion: @escaping (ReadResult<R>) -> Void)
-
End listening on a specified characteristic.
Provides the ability to suppress the failure message to the listen callback. This is useful in the internal implimentation of some of the listening logic, since we want to be able to share the clear logic on a .done exit, but don’t need to send a failure in that case.
Note
Note Currently this can also cancel a regular in-progress read as well, but that behaviour may change down the road.Declaration
Swift
public func endListen(to characteristicIdentifier: CharacteristicIdentifier, error: Error? = nil, completion: ((WriteResult) -> Void)? = nil)
-
Restore a (believed to be) active listening session, so if we start up in response to a notification, we can receive it.
Declaration
Swift
public func restoreListen<R: Receivable>(to characteristicIdentifier: CharacteristicIdentifier, completion: @escaping (ReadResult<R>) -> Void)
-
Ask for the peripheral’s maximum payload length in bytes for a single write request.
Declaration
Swift
public func maximumWriteValueLength(for writeType: CBCharacteristicWriteType) -> Int
-
Captures CoreBluetooth’s did discover services event and pass it to Bluejay’s queue for processing.
Declaration
Swift
public func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?)
-
Captures CoreBluetooth’s did discover characteristics event and pass it to Bluejay’s queue for processing.
Declaration
Swift
public func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?)
-
Captures CoreBluetooth’s did write to charactersitic event and pass it to Bluejay’s queue for processing.
Declaration
Swift
public func peripheral(_ peripheral: CBPeripheral, didWriteValueFor characteristic: CBCharacteristic, error: Error?)
-
Captures CoreBluetooth’s did receive a notification/value from a characteristic event and pass it to Bluejay’s queue for processing.
Declaration
Swift
public func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?)
-
Captures CoreBluetooth’s did turn on or off notification/listening on a characteristic event and pass it to Bluejay’s queue for processing.
Declaration
Swift
public func peripheral(_ peripheral: CBPeripheral, didUpdateNotificationStateFor characteristic: CBCharacteristic, error: Error?)
-
Captures CoreBluetooth’s did read RSSI event and pass it to Bluejay’s queue for processing.
Declaration
Swift
public func peripheral(_ peripheral: CBPeripheral, didReadRSSI RSSI: NSNumber, error: Error?)