Skip to content

Commit

Permalink
Merge branch 'release/0.3.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
NickKibish committed Feb 26, 2024
2 parents 2bab534 + 11bda72 commit 6831f7d
Show file tree
Hide file tree
Showing 15 changed files with 1,417 additions and 525 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ let package = Package(
/// . . .
dependencies: [
// Set the link to the library and choose the version
.package(url: "https://github.com/NordicSemiconductor/IOS-BLE-Library.git", from: "0.1.3"),
.package(url: "https://github.com/NordicSemiconductor/IOS-BLE-Library.git", from: "0.3.1"),
],
targets: [
.target(
Expand All @@ -51,12 +51,12 @@ The library can be installed using CocoaPods.

Add the following line to your Podfile:
```ruby
pod 'iOS-BLE-Library', '~> 0.1.3'
pod 'iOS-BLE-Library', '~> 0.3.1'
```

or
```ruby
pod 'iOS-BLE-Library-Mock', '~> 0.1.3'
pod 'iOS-BLE-Library-Mock', '~> 0.3.1'
```

# Documentation & Examples
Expand Down
87 changes: 39 additions & 48 deletions Sources/iOS-BLE-Library-Mock/Alias.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,59 +38,50 @@ import CoreBluetoothMock
// disabled for Xcode 12.5 beta
//typealias CBPeer = CBMPeer
//typealias CBAttribute = CBMAttribute
public typealias CBCentralManagerFactory = CBMCentralManagerFactory
public typealias CBUUID = CBMUUID
public typealias CBError = CBMError
public typealias CBATTError = CBMATTError
public typealias CBManagerState = CBMManagerState
public typealias CBPeripheralState = CBMPeripheralState
public typealias CBCentralManager = CBMCentralManager
public typealias CBCentralManagerDelegate = CBMCentralManagerDelegate
public typealias CBPeripheral = CBMPeripheral
public typealias CBPeripheralDelegate = CBMPeripheralDelegate
public typealias CBService = CBMService
public typealias CBCharacteristic = CBMCharacteristic
public typealias CBCharacteristicWriteType = CBMCharacteristicWriteType
public typealias CBCharacteristicProperties = CBMCharacteristicProperties
public typealias CBDescriptor = CBMDescriptor
public typealias CBConnectionEvent = CBMConnectionEvent
public typealias CBCentralManagerFactory = CBMCentralManagerFactory
public typealias CBUUID = CBMUUID
public typealias CBError = CBMError
public typealias CBATTError = CBMATTError
public typealias CBManagerState = CBMManagerState
public typealias CBPeripheralState = CBMPeripheralState
public typealias CBCentralManager = CBMCentralManager
public typealias CBCentralManagerDelegate = CBMCentralManagerDelegate
public typealias CBPeripheral = CBMPeripheral
public typealias CBPeripheralDelegate = CBMPeripheralDelegate
public typealias CBService = CBMService
public typealias CBCharacteristic = CBMCharacteristic
public typealias CBCharacteristicWriteType = CBMCharacteristicWriteType
public typealias CBCharacteristicProperties = CBMCharacteristicProperties
public typealias CBDescriptor = CBMDescriptor
public typealias CBConnectionEvent = CBMConnectionEvent
public typealias CBConnectionEventMatchingOption = CBMConnectionEventMatchingOption
@available(iOS 11.0, tvOS 11.0, watchOS 4.0, *)
public typealias CBL2CAPPSM = CBML2CAPPSM
public typealias CBL2CAPPSM = CBML2CAPPSM
@available(iOS 11.0, tvOS 11.0, watchOS 4.0, *)
public typealias CBL2CAPChannel = CBML2CAPChannel
public typealias CBL2CAPChannel = CBML2CAPChannel

public let CBCentralManagerScanOptionAllowDuplicatesKey =
CBMCentralManagerScanOptionAllowDuplicatesKey
public let CBCentralManagerOptionShowPowerAlertKey = CBMCentralManagerOptionShowPowerAlertKey
public let CBCentralManagerOptionRestoreIdentifierKey = CBMCentralManagerOptionRestoreIdentifierKey
public let CBCentralManagerScanOptionSolicitedServiceUUIDsKey =
CBMCentralManagerScanOptionSolicitedServiceUUIDsKey
public let CBConnectPeripheralOptionStartDelayKey = CBMConnectPeripheralOptionStartDelayKey
public let CBCentralManagerScanOptionAllowDuplicatesKey = CBMCentralManagerScanOptionAllowDuplicatesKey
public let CBCentralManagerOptionShowPowerAlertKey = CBMCentralManagerOptionShowPowerAlertKey
public let CBCentralManagerOptionRestoreIdentifierKey = CBMCentralManagerOptionRestoreIdentifierKey
public let CBCentralManagerScanOptionSolicitedServiceUUIDsKey = CBMCentralManagerScanOptionSolicitedServiceUUIDsKey
public let CBConnectPeripheralOptionStartDelayKey = CBMConnectPeripheralOptionStartDelayKey
#if !os(macOS)
@available(iOS 13.0, tvOS 13.0, watchOS 6.0, *)
public let CBConnectPeripheralOptionRequiresANCS = CBMConnectPeripheralOptionRequiresANCS
@available(iOS 13.0, tvOS 13.0, watchOS 6.0, *)
public let CBConnectPeripheralOptionRequiresANCS = CBMConnectPeripheralOptionRequiresANCS
#endif
public let CBCentralManagerRestoredStatePeripheralsKey =
CBMCentralManagerRestoredStatePeripheralsKey
public let CBCentralManagerRestoredStateScanServicesKey =
CBMCentralManagerRestoredStateScanServicesKey
public let CBCentralManagerRestoredStateScanOptionsKey =
CBMCentralManagerRestoredStateScanOptionsKey
public let CBCentralManagerRestoredStatePeripheralsKey = CBMCentralManagerRestoredStatePeripheralsKey
public let CBCentralManagerRestoredStateScanServicesKey = CBMCentralManagerRestoredStateScanServicesKey
public let CBCentralManagerRestoredStateScanOptionsKey = CBMCentralManagerRestoredStateScanOptionsKey

public let CBAdvertisementDataLocalNameKey = CBMAdvertisementDataLocalNameKey
public let CBAdvertisementDataServiceUUIDsKey = CBMAdvertisementDataServiceUUIDsKey
public let CBAdvertisementDataIsConnectable = CBMAdvertisementDataIsConnectable
public let CBAdvertisementDataTxPowerLevelKey = CBMAdvertisementDataTxPowerLevelKey
public let CBAdvertisementDataServiceDataKey = CBMAdvertisementDataServiceDataKey
public let CBAdvertisementDataManufacturerDataKey = CBMAdvertisementDataManufacturerDataKey
public let CBAdvertisementDataOverflowServiceUUIDsKey = CBMAdvertisementDataOverflowServiceUUIDsKey
public let CBAdvertisementDataSolicitedServiceUUIDsKey =
CBMAdvertisementDataSolicitedServiceUUIDsKey
public let CBAdvertisementDataLocalNameKey = CBMAdvertisementDataLocalNameKey
public let CBAdvertisementDataServiceUUIDsKey = CBMAdvertisementDataServiceUUIDsKey
public let CBAdvertisementDataIsConnectable = CBMAdvertisementDataIsConnectable
public let CBAdvertisementDataTxPowerLevelKey = CBMAdvertisementDataTxPowerLevelKey
public let CBAdvertisementDataServiceDataKey = CBMAdvertisementDataServiceDataKey
public let CBAdvertisementDataManufacturerDataKey = CBMAdvertisementDataManufacturerDataKey
public let CBAdvertisementDataOverflowServiceUUIDsKey = CBMAdvertisementDataOverflowServiceUUIDsKey
public let CBAdvertisementDataSolicitedServiceUUIDsKey = CBMAdvertisementDataSolicitedServiceUUIDsKey

public let CBConnectPeripheralOptionNotifyOnConnectionKey =
CBMConnectPeripheralOptionNotifyOnConnectionKey
public let CBConnectPeripheralOptionNotifyOnDisconnectionKey =
CBMConnectPeripheralOptionNotifyOnDisconnectionKey
public let CBConnectPeripheralOptionNotifyOnNotificationKey =
CBMConnectPeripheralOptionNotifyOnNotificationKey
public let CBConnectPeripheralOptionNotifyOnConnectionKey = CBMConnectPeripheralOptionNotifyOnConnectionKey
public let CBConnectPeripheralOptionNotifyOnDisconnectionKey = CBMConnectPeripheralOptionNotifyOnDisconnectionKey
public let CBConnectPeripheralOptionNotifyOnNotificationKey = CBMConnectPeripheralOptionNotifyOnNotificationKey
64 changes: 30 additions & 34 deletions Sources/iOS-BLE-Library-Mock/CentralManager/CentralManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ extension CentralManager {
public var localizedDescription: String {
switch self {
case .wrongManager:
return
"Incorrect manager instance provided. Delegate must be of type ReactiveCentralManagerDelegate."
return "Incorrect manager instance provided. Delegate must be of type ReactiveCentralManagerDelegate."
case .badState(let state):
return "Bad state: \(state)."
case .unknownError:
Expand Down Expand Up @@ -55,7 +54,7 @@ private class Observer: NSObject {
}

/// A Custom Central Manager class.
///
///
/// It wraps the standard CBCentralManager and has similar API. However, instead of using delegate, it uses publishers, thus bringing the reactive programming paradigm to the CoreBluetooth framework.
public class CentralManager {
private let isScanningSubject = CurrentValueSubject<Bool, Never>(false)
Expand All @@ -64,7 +63,7 @@ public class CentralManager {

/// The underlying CBCentralManager instance.
public let centralManager: CBCentralManager

/// The reactive delegate for the ``centralManager``.
public let centralManagerDelegate: ReactiveCentralManagerDelegate

Expand All @@ -74,12 +73,10 @@ public class CentralManager {
/// - queue: The queue to perform operations on. Default is the main queue.
public init(
centralManagerDelegate: ReactiveCentralManagerDelegate =
ReactiveCentralManagerDelegate(), queue: DispatchQueue = .main,
options: [String: Any]? = nil
ReactiveCentralManagerDelegate(), queue: DispatchQueue = .main, options: [String : Any]? = nil
) {
self.centralManagerDelegate = centralManagerDelegate
self.centralManager = CBMCentralManagerFactory.instance(
delegate: centralManagerDelegate, queue: queue)
self.centralManager = CBMCentralManagerFactory.instance(delegate: centralManagerDelegate, queue: queue)
observer.setup()
}

Expand Down Expand Up @@ -112,17 +109,17 @@ extension CentralManager {
/// If the peripheral was disconnected successfully, the publisher finishes without error.
/// If the connection was unsuccessful or disconnection returns an error (e.g., peripheral disconnected unexpectedly),
/// the publisher finishes with an error.
///
/// Use ``CentralManager/connect(_:options:)`` to connect to a peripheral.
/// The returned publisher will emit the connected peripheral or an error if the connection fails.
/// The publisher will not complete until the peripheral is disconnected.
/// If the connection fails, or the peripheral is unexpectedly disconnected, the publisher will fail with an error.
///
/// ```swift
/// centralManager.connect(peripheral)
/// .sink { completion in
/// switch completion {
/// case .finished:
///
/// Use ``CentralManager/connect(_:options:)`` to connect to a peripheral.
/// The returned publisher will emit the connected peripheral or an error if the connection fails.
/// The publisher will not complete until the peripheral is disconnected.
/// If the connection fails, or the peripheral is unexpectedly disconnected, the publisher will fail with an error.
///
/// ```swift
/// centralManager.connect(peripheral)
/// .sink { completion in
/// switch completion {
/// case .finished:
/// print("Peripheral disconnected successfully")
/// case .failure(let error):
/// print("Error: \(error)")
Expand Down Expand Up @@ -155,16 +152,15 @@ extension CentralManager {
.bluetooth {
self.centralManager.connect(peripheral, options: options)
}
.autoconnect()
.eraseToAnyPublisher()
.autoconnect()
.eraseToAnyPublisher()
}

/// Cancels the connection with the specified peripheral.
/// - Parameter peripheral: The peripheral to disconnect from.
/// - Returns: A publisher that emits the disconnected peripheral.
public func cancelPeripheralConnection(_ peripheral: CBPeripheral) -> AnyPublisher<
CBPeripheral, Error
> {
public func cancelPeripheralConnection(_ peripheral: CBPeripheral) -> AnyPublisher<CBPeripheral, Error>
{
return self.disconnectedPeripheralsChannel
.tryFilter { r in
guard r.0.identifier == peripheral.identifier else {
Expand All @@ -179,17 +175,17 @@ extension CentralManager {
}
.map { $0.0 }
.first()
.bluetooth {
self.centralManager.cancelPeripheralConnection(peripheral)
}
.autoconnect()
.eraseToAnyPublisher()
.bluetooth {
self.centralManager.cancelPeripheralConnection(peripheral)
}
.autoconnect()
.eraseToAnyPublisher()
}
}

// MARK: Retrieving Lists of Peripherals
extension CentralManager {
#warning("check `connect` method")
#warning("check `connect` method")
/// Returns a list of the peripherals connected to the system whose
/// services match a given set of criteria.
///
Expand Down Expand Up @@ -222,9 +218,9 @@ extension CentralManager {
extension CentralManager {
#warning("Question: Should we throw an error if the scan is already running?")
/// Initiates a scan for peripherals with the specified services.
///
///
/// Calling this method stops an ongoing scan if it is already running and finishes the publisher returned by ``scanForPeripherals(withServices:)``.
///
///
/// - Parameter services: The services to scan for.
/// - Returns: A publisher that emits scan results or an error.
public func scanForPeripherals(withServices services: [CBUUID]?)
Expand Down Expand Up @@ -254,8 +250,8 @@ extension CentralManager {
.bluetooth {
self.centralManager.scanForPeripherals(withServices: services)
}
.autoconnect()
.eraseToAnyPublisher()
.autoconnect()
.eraseToAnyPublisher()
}

/// Stops an ongoing scan for peripherals.
Expand Down
Loading

0 comments on commit 6831f7d

Please sign in to comment.