Gormsson
public final class Gormsson : NSObject
Gormsson is a BLE manager with blocks and auto cast type.
-
The current peripheral is discovering his services and characteristics.
Declaration
Swift
internal var isDiscovering: Bool
-
Number of services that are currently discovering.
Declaration
Swift
internal var discoveringService: Int
-
The pending requests that wait to be resolved.
Declaration
Swift
internal var pendingRequests: [GattRequest]
-
The current active requests (notify requests).
Declaration
Swift
internal var currentRequests: [GattRequest]
-
The block to call each time a peripheral is found.
Declaration
Swift
internal var didDiscoverBlock: ((CBPeripheral, GattAdvertisement) -> Void)?
-
The current connected peripheral.
Declaration
Swift
public var current: CBPeripheral?
-
The current state of the manager.
Declaration
Swift
@objc public dynamic var state: GormssonState
-
Init a new Gormsson manager
Declaration
Swift
public init(queue: DispatchQueue? = nil, options: [String : Any]? = nil)
Parameters
queue
The dispatch queue on which the events will be dispatched. If nil, the main queue will be used.
options
An optional dictionary specifying options for the manager
-
Clean up
Declaration
Swift
deinit
-
Scans for peripherals that are advertising services.
Declaration
Swift
public func scan(_ services: [GattService]? = nil, options: [String: Any]? = nil, didDiscover: @escaping (CBPeripheral, GattAdvertisement) -> Void)
Parameters
services
An array of services that the app is interested in. In this case, each service represents the UUID of a service that a peripheral is advertising.
options
An optional dictionary specifying options to customize the scan. For available options, see Peripheral Scanning Options.
didDiscover
A block invoked when the manager discovers a peripheral while scanning.
-
Asks the central manager to stop scanning for peripherals.
Declaration
Swift
public func stopScan()
-
Establishes a local connection to a peripheral.
Declaration
Swift
public func connect(_ peripheral: CBPeripheral)
Parameters
peripheral
The peripheral to which the central is attempting to connect.
-
Cancels an active or pending local connection to the current peripheral.
Declaration
Swift
public func disconnect()
-
Send a new scan if the first one was too early.
Declaration
Swift
internal func rescan()
-
Gets the CBCharacteristic of the current peripheral or nil if not in.
Declaration
Swift
internal func get(_ characteristic: CharacteristicProtocol) -> CBCharacteristic?
-
Reads the value of a characteristic from a request.
Declaration
Swift
internal func read(_ request: GattRequest, append: Bool = true)
-
Starts notifications for the value of a characteristic from a request.
Declaration
Swift
internal func notify(_ request: GattRequest)
-
Writes the value of a characteristic from a request.
Declaration
Swift
internal func write(_ request: GattRequest)
-
Invoked when the central manager’s state is updated.
Declaration
Swift
public func centralManagerDidUpdateState(_ central: CBCentralManager)
-
Invoked when the central manager discovers a peripheral while scanning.
Declaration
Swift
public func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String: Any], rssi RSSI: NSNumber)
-
Invoked when an existing connection with a peripheral is torn down.
Declaration
Swift
public func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: Error?)
-
Invoked when a connection is successfully created with a peripheral.
Declaration
Swift
public func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral)
-
Starts notifications or indications for the value of a base characteristic.
Declaration
Swift
public func notify(_ characteristic: GattCharacteristic, success: @escaping (DataInitializable?) -> Void, error: @escaping (Error?) -> Void)
-
Starts notifications or indications for the value of a base characteristic.
Declaration
Swift
public func notify(_ characteristic: CharacteristicProtocol, success: @escaping (DataInitializable?) -> Void, error: @escaping (Error?) -> Void)
-
Stops notifications or indications for the value of a custom characteristic.
Declaration
Swift
public func stopNotify(_ characteristic: GattCharacteristic)
-
Stops notifications or indications for the value of a custom characteristic.
Declaration
Swift
public func stopNotify(_ characteristic: CharacteristicProtocol)
-
Invoked when you discover the peripheral’s available services.
Declaration
Swift
public func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?)
-
Invoked when you discover the characteristics of a specified service.
Declaration
Swift
public func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?)
-
Invoked when you retrieve a specified characteristic’s value, or when the peripheral device notifies your app that the characteristic’s value has changed.
Declaration
Swift
public func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?)
-
Invoked when the peripheral receives a request to start or stop providing notifications for a specified characteristic’s value.
Declaration
Swift
public func peripheral(_ peripheral: CBPeripheral, didUpdateNotificationStateFor characteristic: CBCharacteristic, error: Error?)
-
Invoked when you write data to a characteristic’s value.
Declaration
Swift
public func peripheral(_ peripheral: CBPeripheral, didWriteValueFor characteristic: CBCharacteristic, error: Error?)
-
Reads the value of a base characteristic.
Declaration
Swift
public func read(_ characteristic: GattCharacteristic, success: @escaping (DataInitializable?) -> Void, error: @escaping (Error?) -> Void)
-
Reads the value of a custom characteristic.
Declaration
Swift
public func read(_ characteristic: CharacteristicProtocol, success: @escaping (DataInitializable?) -> Void, error: @escaping (Error?) -> Void)
-
Writes the value of a base characteristic.
Declaration
Swift
public func write(_ characteristic: GattCharacteristic, value: DataConvertible, success: @escaping (DataInitializable?) -> Void, error: @escaping (Error?) -> Void)
-
Writes the value of a custom characteristic.
Declaration
Swift
public func write(_ characteristic: CharacteristicProtocol, value: DataConvertible, success: @escaping (DataInitializable?) -> Void, error: @escaping (Error?) -> Void)