RVS_BlueThoth

public class RVS_BlueThoth : NSObject, RVS_SequenceProtocol

This is the main class that is instantiated in order to implement the Bluetooth subsystem. This acts as a Core Bluetooth Central, and aggregates Peripherals, which, in turn, aggregate Services, which, in turn, aggregate Characteristics, which, in turn, may aggregate Descriptors.

  • The Central Manager Delegate object.

    Declaration

    Swift

    public weak var delegate: CGA_BlueThoth_Delegate?
  • This is used to reference an “owning instance” of this instance, and it should be a CGA_Class_Protocol

    Declaration

    Swift

    public weak var parent: CGA_Class_Protocol?
  • Returns true, if the current state of the Bluetooth system is powered on.

    Declaration

    Swift

    public var isBTAvailable: Bool { get }
  • If true (default), then scanning is done with duplicate filtering on, which reduces the number of times the discovery callback is made.

    Declaration

    Swift

    public var duplicateFilteringIsOn: Bool
  • This Bool will be true, if we only want to discover devices that can be connected. Default is false.

    Declaration

    Swift

    public var discoverOnlyConnectablePeripherals: Bool
  • This Bool will be true, if we will allow devices that don’t broadcast names to be discovered. Default is false.

    Declaration

    Swift

    public var allowEmptyNames: Bool
  • This is a “Minimum RSSI Level” for filtering. If a device is discovered with an RSSI less than this, it is ignored. The Default is -100. It can be changed by the SDK user, for subsequent scans.

    Declaration

    Swift

    public var minimumRSSILevelIndBm: Int
  • This will hold BLE Peripherals, as they are being “loaded.” Once they are “complete,” they go into the main collection, wrapped in our class.

    Declaration

    Swift

    public var stagedBLEPeripherals: [RVS_BlueThoth.DiscoveryData]
  • This will hold BLE Peripherals that have been marked as “ignored.”

    Declaration

    Swift

    public var ignoredBLEPeripherals: [RVS_BlueThoth.DiscoveryData]
  • This will contain any required scan criteria.

    Declaration

    Swift

    public var scanCriteria: ScanCriteria?
  • We aggregate Peripherals.

    Declaration

    Swift

    public typealias Element = CGA_Bluetooth_Peripheral
  • This holds our cached Array of Peripheral instances.

    Declaration

    Swift

    public var sequence_contents: Array<Element>
  • This is the indicator as to whether or not the Bluetooth subsystem is actiively scanning for Peripherals.

    This is read-only. Use the startScanning(withServices:) and stopScanning() methods to change the scanning state.

    Declaration

    Swift

    public var isScanning: Bool { get }
  • This is how many seconds we wait, before declaring a timeout. Default is 5 seconds, but the value can be changed.

    Declaration

    Swift

    public var timeoutInSeconds: TimeInterval { get set }
  • The required init, with a “primed” sequence.

    Declaration

    Swift

    public required init(sequence_contents inSequenceContents: [Element])

    Parameters

    sequence_contents

    The initial value of the Array cache. It should be empty.

Public Instance Methods

  • Called to report an error.

    Declaration

    Swift

    public func reportError(_ inError: CGA_Errors)

    Parameters

    inError

    The error being reported.

  • This is the init that should always be used.

    Convenience init. This allows “no parameter” inits, and ones that only have the queue and/or the delegate. This will call the delegate’s updateFrom(_:) method, upon starting.

    Declaration

    Swift

    public convenience init(delegate inDelegate: CGA_BlueThoth_Delegate? = nil, scanCriteria inScanCriteria: ScanCriteria? = nil, queue inQueue: DispatchQueue? = nil)

    Parameters

    delegate

    The delegate instance.

    scanCriteria

    If there are particular scan criteria to be applied to the discovery process, they are supplied here. If left alone, it will be nil, and all entities will be searched.

    queue

    The queue to be used for this instance. If not specified, the main thread is used.

  • Asks the Central Manager to start scanning for Peripherals.

    Declaration

    Swift

    @discardableResult
    public func startScanning(withServices inWithServices: [String]? = nil, duplicateFilteringIsOn inDuplicateFilteringIsOn: Bool = true) -> Bool

    Parameters

    withServices

    An Array of Strings, with the UUID strings. This is optional, and can be left out, in which case all services will be scanned.

    duplicateFilteringIsOn

    If true, then scans will be made with duplicate filtering, which reduces the number of times the discovery callback is made.

    Return Value

    True, if the scan attempt was made (not a guarantee of success, though). Can be ignored.

  • Asks the Central Manager to start scanning for Peripherals, but reuse any saved filters (as opposed to supplying them).

    Declaration

    Swift

    @discardableResult
    public func restartScanning() -> Bool

    Return Value

    True, if the scan attempt was made (not a guarantee of success, though). Can be ignored.

  • Asks the Central Manager to stop scanning for Peripherals.

    Declaration

    Swift

    @discardableResult
    public func stopScanning() -> Bool

    Return Value

    True, if the attempt was made (not a guarantee of success, though). Can be ignored.

  • This eliminates all of the stored results, and asks the Bluetooth subsystem to start over from scratch.

    Declaration

    Swift

    public func startOver(_ inScan: Bool? = nil)

    Parameters

    inScan

    OPTIONAL: If true, then the scan will be started afterwards. If false, then the scan will not be started, even if it was scanning. If not provided, then the scanning will restart, if it was previously scanning.

  • This forces disconnects for all Peripherals.

    Declaration

    Swift

    public func disconnectAllPeripherals()
  • Called to initiate a connection (and discovery process) with the peripheral.

    Declaration

    Swift

    @discardableResult
    public func connect(_ inPeripheral: DiscoveryData?) -> Bool

    Parameters

    inPeripheral

    The Peripheral (CB) to connect, as the opaque DiscoveryData type.

    Return Value

    True, if the connection attempt was made (not a guarantee of success, though). Can be ignored.

  • Called to terminate a connection with the peripheral.

    Declaration

    Swift

    @discardableResult
    public func disconnect(_ inPeripheral: DiscoveryData) -> Bool

    Parameters

    inPeripheral

    The Peripheral (CB) to connect.

    Return Value

    True, if the disconnection attempt was made (not a guarantee of success, though). Can be ignored.

  • This searches the hierarchy, and will return any instance that has an ID that matches the string passed in. This could be a Peripheral, Service, Characteristic or Descriptor. The response will need to be cast.

    Declaration

    Swift

    public func findEntityByUUIDString(_ inUUIDString: String) -> CGA_Class_Protocol?

    Parameters

    inUUIDString

    The String for the UUID for which we are searching.

    Return Value

    Any element in the hierarchy with a UUID that matches the one passed in, or nil.

ScanCriteria Struct

  • This is the struct that we use to narrow the search criteria for new instances of the CGA_Bluetooth_CentralManager class.

    If you will not be looking for particular Bluetooth instances, then leave the corresponding property nil, or empty.

    All members are String, but these will be converted internally into CBUUIDs.

    These are applied across the board. For example, if you specify a Service, then ALL scans will filter for that Service, and if you specify a Characteristic, then ALL Services, for ALL peripherals, will be scanned for that Characteristic.

    See more

    Declaration

    Swift

    public struct ScanCriteria

AdvertisementData Struct

  • This struct allows us to apply some data interpretation to the advertisement data.

    See more

    Declaration

    Swift

    public struct AdvertisementData

DiscoveryData Class

  • This is a class, as opposed to a struct, because I want to make sure that it is referenced, and not copied.

    See more

    Declaration

    Swift

    public class DiscoveryData