Skip to content

Commit 6831f7d

Browse files
committed
Merge branch 'release/0.3.1'
2 parents 2bab534 + 11bda72 commit 6831f7d

15 files changed

+1417
-525
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ let package = Package(
2424
/// . . .
2525
dependencies: [
2626
// Set the link to the library and choose the version
27-
.package(url: "https://github.com/NordicSemiconductor/IOS-BLE-Library.git", from: "0.1.3"),
27+
.package(url: "https://github.com/NordicSemiconductor/IOS-BLE-Library.git", from: "0.3.1"),
2828
],
2929
targets: [
3030
.target(
@@ -51,12 +51,12 @@ The library can be installed using CocoaPods.
5151

5252
Add the following line to your Podfile:
5353
```ruby
54-
pod 'iOS-BLE-Library', '~> 0.1.3'
54+
pod 'iOS-BLE-Library', '~> 0.3.1'
5555
```
5656

5757
or
5858
```ruby
59-
pod 'iOS-BLE-Library-Mock', '~> 0.1.3'
59+
pod 'iOS-BLE-Library-Mock', '~> 0.3.1'
6060
```
6161

6262
# Documentation & Examples

Sources/iOS-BLE-Library-Mock/Alias.swift

+39-48
Original file line numberDiff line numberDiff line change
@@ -38,59 +38,50 @@ import CoreBluetoothMock
3838
// disabled for Xcode 12.5 beta
3939
//typealias CBPeer = CBMPeer
4040
//typealias CBAttribute = CBMAttribute
41-
public typealias CBCentralManagerFactory = CBMCentralManagerFactory
42-
public typealias CBUUID = CBMUUID
43-
public typealias CBError = CBMError
44-
public typealias CBATTError = CBMATTError
45-
public typealias CBManagerState = CBMManagerState
46-
public typealias CBPeripheralState = CBMPeripheralState
47-
public typealias CBCentralManager = CBMCentralManager
48-
public typealias CBCentralManagerDelegate = CBMCentralManagerDelegate
49-
public typealias CBPeripheral = CBMPeripheral
50-
public typealias CBPeripheralDelegate = CBMPeripheralDelegate
51-
public typealias CBService = CBMService
52-
public typealias CBCharacteristic = CBMCharacteristic
53-
public typealias CBCharacteristicWriteType = CBMCharacteristicWriteType
54-
public typealias CBCharacteristicProperties = CBMCharacteristicProperties
55-
public typealias CBDescriptor = CBMDescriptor
56-
public typealias CBConnectionEvent = CBMConnectionEvent
41+
public typealias CBCentralManagerFactory = CBMCentralManagerFactory
42+
public typealias CBUUID = CBMUUID
43+
public typealias CBError = CBMError
44+
public typealias CBATTError = CBMATTError
45+
public typealias CBManagerState = CBMManagerState
46+
public typealias CBPeripheralState = CBMPeripheralState
47+
public typealias CBCentralManager = CBMCentralManager
48+
public typealias CBCentralManagerDelegate = CBMCentralManagerDelegate
49+
public typealias CBPeripheral = CBMPeripheral
50+
public typealias CBPeripheralDelegate = CBMPeripheralDelegate
51+
public typealias CBService = CBMService
52+
public typealias CBCharacteristic = CBMCharacteristic
53+
public typealias CBCharacteristicWriteType = CBMCharacteristicWriteType
54+
public typealias CBCharacteristicProperties = CBMCharacteristicProperties
55+
public typealias CBDescriptor = CBMDescriptor
56+
public typealias CBConnectionEvent = CBMConnectionEvent
5757
public typealias CBConnectionEventMatchingOption = CBMConnectionEventMatchingOption
5858
@available(iOS 11.0, tvOS 11.0, watchOS 4.0, *)
59-
public typealias CBL2CAPPSM = CBML2CAPPSM
59+
public typealias CBL2CAPPSM = CBML2CAPPSM
6060
@available(iOS 11.0, tvOS 11.0, watchOS 4.0, *)
61-
public typealias CBL2CAPChannel = CBML2CAPChannel
61+
public typealias CBL2CAPChannel = CBML2CAPChannel
6262

63-
public let CBCentralManagerScanOptionAllowDuplicatesKey =
64-
CBMCentralManagerScanOptionAllowDuplicatesKey
65-
public let CBCentralManagerOptionShowPowerAlertKey = CBMCentralManagerOptionShowPowerAlertKey
66-
public let CBCentralManagerOptionRestoreIdentifierKey = CBMCentralManagerOptionRestoreIdentifierKey
67-
public let CBCentralManagerScanOptionSolicitedServiceUUIDsKey =
68-
CBMCentralManagerScanOptionSolicitedServiceUUIDsKey
69-
public let CBConnectPeripheralOptionStartDelayKey = CBMConnectPeripheralOptionStartDelayKey
63+
public let CBCentralManagerScanOptionAllowDuplicatesKey = CBMCentralManagerScanOptionAllowDuplicatesKey
64+
public let CBCentralManagerOptionShowPowerAlertKey = CBMCentralManagerOptionShowPowerAlertKey
65+
public let CBCentralManagerOptionRestoreIdentifierKey = CBMCentralManagerOptionRestoreIdentifierKey
66+
public let CBCentralManagerScanOptionSolicitedServiceUUIDsKey = CBMCentralManagerScanOptionSolicitedServiceUUIDsKey
67+
public let CBConnectPeripheralOptionStartDelayKey = CBMConnectPeripheralOptionStartDelayKey
7068
#if !os(macOS)
71-
@available(iOS 13.0, tvOS 13.0, watchOS 6.0, *)
72-
public let CBConnectPeripheralOptionRequiresANCS = CBMConnectPeripheralOptionRequiresANCS
69+
@available(iOS 13.0, tvOS 13.0, watchOS 6.0, *)
70+
public let CBConnectPeripheralOptionRequiresANCS = CBMConnectPeripheralOptionRequiresANCS
7371
#endif
74-
public let CBCentralManagerRestoredStatePeripheralsKey =
75-
CBMCentralManagerRestoredStatePeripheralsKey
76-
public let CBCentralManagerRestoredStateScanServicesKey =
77-
CBMCentralManagerRestoredStateScanServicesKey
78-
public let CBCentralManagerRestoredStateScanOptionsKey =
79-
CBMCentralManagerRestoredStateScanOptionsKey
72+
public let CBCentralManagerRestoredStatePeripheralsKey = CBMCentralManagerRestoredStatePeripheralsKey
73+
public let CBCentralManagerRestoredStateScanServicesKey = CBMCentralManagerRestoredStateScanServicesKey
74+
public let CBCentralManagerRestoredStateScanOptionsKey = CBMCentralManagerRestoredStateScanOptionsKey
8075

81-
public let CBAdvertisementDataLocalNameKey = CBMAdvertisementDataLocalNameKey
82-
public let CBAdvertisementDataServiceUUIDsKey = CBMAdvertisementDataServiceUUIDsKey
83-
public let CBAdvertisementDataIsConnectable = CBMAdvertisementDataIsConnectable
84-
public let CBAdvertisementDataTxPowerLevelKey = CBMAdvertisementDataTxPowerLevelKey
85-
public let CBAdvertisementDataServiceDataKey = CBMAdvertisementDataServiceDataKey
86-
public let CBAdvertisementDataManufacturerDataKey = CBMAdvertisementDataManufacturerDataKey
87-
public let CBAdvertisementDataOverflowServiceUUIDsKey = CBMAdvertisementDataOverflowServiceUUIDsKey
88-
public let CBAdvertisementDataSolicitedServiceUUIDsKey =
89-
CBMAdvertisementDataSolicitedServiceUUIDsKey
76+
public let CBAdvertisementDataLocalNameKey = CBMAdvertisementDataLocalNameKey
77+
public let CBAdvertisementDataServiceUUIDsKey = CBMAdvertisementDataServiceUUIDsKey
78+
public let CBAdvertisementDataIsConnectable = CBMAdvertisementDataIsConnectable
79+
public let CBAdvertisementDataTxPowerLevelKey = CBMAdvertisementDataTxPowerLevelKey
80+
public let CBAdvertisementDataServiceDataKey = CBMAdvertisementDataServiceDataKey
81+
public let CBAdvertisementDataManufacturerDataKey = CBMAdvertisementDataManufacturerDataKey
82+
public let CBAdvertisementDataOverflowServiceUUIDsKey = CBMAdvertisementDataOverflowServiceUUIDsKey
83+
public let CBAdvertisementDataSolicitedServiceUUIDsKey = CBMAdvertisementDataSolicitedServiceUUIDsKey
9084

91-
public let CBConnectPeripheralOptionNotifyOnConnectionKey =
92-
CBMConnectPeripheralOptionNotifyOnConnectionKey
93-
public let CBConnectPeripheralOptionNotifyOnDisconnectionKey =
94-
CBMConnectPeripheralOptionNotifyOnDisconnectionKey
95-
public let CBConnectPeripheralOptionNotifyOnNotificationKey =
96-
CBMConnectPeripheralOptionNotifyOnNotificationKey
85+
public let CBConnectPeripheralOptionNotifyOnConnectionKey = CBMConnectPeripheralOptionNotifyOnConnectionKey
86+
public let CBConnectPeripheralOptionNotifyOnDisconnectionKey = CBMConnectPeripheralOptionNotifyOnDisconnectionKey
87+
public let CBConnectPeripheralOptionNotifyOnNotificationKey = CBMConnectPeripheralOptionNotifyOnNotificationKey

Sources/iOS-BLE-Library-Mock/CentralManager/CentralManager.swift

+30-34
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ extension CentralManager {
1818
public var localizedDescription: String {
1919
switch self {
2020
case .wrongManager:
21-
return
22-
"Incorrect manager instance provided. Delegate must be of type ReactiveCentralManagerDelegate."
21+
return "Incorrect manager instance provided. Delegate must be of type ReactiveCentralManagerDelegate."
2322
case .badState(let state):
2423
return "Bad state: \(state)."
2524
case .unknownError:
@@ -55,7 +54,7 @@ private class Observer: NSObject {
5554
}
5655

5756
/// A Custom Central Manager class.
58-
///
57+
///
5958
/// 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.
6059
public class CentralManager {
6160
private let isScanningSubject = CurrentValueSubject<Bool, Never>(false)
@@ -64,7 +63,7 @@ public class CentralManager {
6463

6564
/// The underlying CBCentralManager instance.
6665
public let centralManager: CBCentralManager
67-
66+
6867
/// The reactive delegate for the ``centralManager``.
6968
public let centralManagerDelegate: ReactiveCentralManagerDelegate
7069

@@ -74,12 +73,10 @@ public class CentralManager {
7473
/// - queue: The queue to perform operations on. Default is the main queue.
7574
public init(
7675
centralManagerDelegate: ReactiveCentralManagerDelegate =
77-
ReactiveCentralManagerDelegate(), queue: DispatchQueue = .main,
78-
options: [String: Any]? = nil
76+
ReactiveCentralManagerDelegate(), queue: DispatchQueue = .main, options: [String : Any]? = nil
7977
) {
8078
self.centralManagerDelegate = centralManagerDelegate
81-
self.centralManager = CBMCentralManagerFactory.instance(
82-
delegate: centralManagerDelegate, queue: queue)
79+
self.centralManager = CBMCentralManagerFactory.instance(delegate: centralManagerDelegate, queue: queue)
8380
observer.setup()
8481
}
8582

@@ -112,17 +109,17 @@ extension CentralManager {
112109
/// If the peripheral was disconnected successfully, the publisher finishes without error.
113110
/// If the connection was unsuccessful or disconnection returns an error (e.g., peripheral disconnected unexpectedly),
114111
/// the publisher finishes with an error.
115-
///
116-
/// Use ``CentralManager/connect(_:options:)`` to connect to a peripheral.
117-
/// The returned publisher will emit the connected peripheral or an error if the connection fails.
118-
/// The publisher will not complete until the peripheral is disconnected.
119-
/// If the connection fails, or the peripheral is unexpectedly disconnected, the publisher will fail with an error.
120-
///
121-
/// ```swift
122-
/// centralManager.connect(peripheral)
123-
/// .sink { completion in
124-
/// switch completion {
125-
/// case .finished:
112+
///
113+
/// Use ``CentralManager/connect(_:options:)`` to connect to a peripheral.
114+
/// The returned publisher will emit the connected peripheral or an error if the connection fails.
115+
/// The publisher will not complete until the peripheral is disconnected.
116+
/// If the connection fails, or the peripheral is unexpectedly disconnected, the publisher will fail with an error.
117+
///
118+
/// ```swift
119+
/// centralManager.connect(peripheral)
120+
/// .sink { completion in
121+
/// switch completion {
122+
/// case .finished:
126123
/// print("Peripheral disconnected successfully")
127124
/// case .failure(let error):
128125
/// print("Error: \(error)")
@@ -155,16 +152,15 @@ extension CentralManager {
155152
.bluetooth {
156153
self.centralManager.connect(peripheral, options: options)
157154
}
158-
.autoconnect()
159-
.eraseToAnyPublisher()
155+
.autoconnect()
156+
.eraseToAnyPublisher()
160157
}
161158

162159
/// Cancels the connection with the specified peripheral.
163160
/// - Parameter peripheral: The peripheral to disconnect from.
164161
/// - Returns: A publisher that emits the disconnected peripheral.
165-
public func cancelPeripheralConnection(_ peripheral: CBPeripheral) -> AnyPublisher<
166-
CBPeripheral, Error
167-
> {
162+
public func cancelPeripheralConnection(_ peripheral: CBPeripheral) -> AnyPublisher<CBPeripheral, Error>
163+
{
168164
return self.disconnectedPeripheralsChannel
169165
.tryFilter { r in
170166
guard r.0.identifier == peripheral.identifier else {
@@ -179,17 +175,17 @@ extension CentralManager {
179175
}
180176
.map { $0.0 }
181177
.first()
182-
.bluetooth {
183-
self.centralManager.cancelPeripheralConnection(peripheral)
184-
}
185-
.autoconnect()
186-
.eraseToAnyPublisher()
178+
.bluetooth {
179+
self.centralManager.cancelPeripheralConnection(peripheral)
180+
}
181+
.autoconnect()
182+
.eraseToAnyPublisher()
187183
}
188184
}
189185

190186
// MARK: Retrieving Lists of Peripherals
191187
extension CentralManager {
192-
#warning("check `connect` method")
188+
#warning("check `connect` method")
193189
/// Returns a list of the peripherals connected to the system whose
194190
/// services match a given set of criteria.
195191
///
@@ -222,9 +218,9 @@ extension CentralManager {
222218
extension CentralManager {
223219
#warning("Question: Should we throw an error if the scan is already running?")
224220
/// Initiates a scan for peripherals with the specified services.
225-
///
221+
///
226222
/// Calling this method stops an ongoing scan if it is already running and finishes the publisher returned by ``scanForPeripherals(withServices:)``.
227-
///
223+
///
228224
/// - Parameter services: The services to scan for.
229225
/// - Returns: A publisher that emits scan results or an error.
230226
public func scanForPeripherals(withServices services: [CBUUID]?)
@@ -254,8 +250,8 @@ extension CentralManager {
254250
.bluetooth {
255251
self.centralManager.scanForPeripherals(withServices: services)
256252
}
257-
.autoconnect()
258-
.eraseToAnyPublisher()
253+
.autoconnect()
254+
.eraseToAnyPublisher()
259255
}
260256

261257
/// Stops an ongoing scan for peripherals.

0 commit comments

Comments
 (0)