Skip to content

Commit 9558462

Browse files
committed
Merge branch 'release/0.3.0'
2 parents fdef4b0 + b5252e5 commit 9558462

File tree

551 files changed

+1729
-534
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

551 files changed

+1729
-534
lines changed

.swiftpm/xcode/xcshareddata/xcschemes/iOS-BLE-Library-Mock.xcscheme

+9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@
55
<BuildAction
66
parallelizeBuildables = "YES"
77
buildImplicitDependencies = "YES">
8+
<PreActions>
9+
<ExecutionAction
10+
ActionType = "Xcode.IDEStandardExecutionActionsCore.ExecutionActionType.ShellScriptAction">
11+
<ActionContent
12+
title = "Run Script"
13+
scriptText = "export PATH=/usr/local/bin:$PATH&#10;cd &quot;$WORKSPACE_PATH&quot;/../../../IOS-BLE-Library/&#10;&#10;python3 code_gen/code_gen.py Sources&#10;">
14+
</ActionContent>
15+
</ExecutionAction>
16+
</PreActions>
817
<BuildActionEntries>
918
<BuildActionEntry
1019
buildForTesting = "YES"

.swiftpm/xcode/xcshareddata/xcschemes/iOS-BLE-Library.xcscheme

+12-49
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1420"
4-
version = "1.3">
3+
LastUpgradeVersion = "1500"
4+
version = "1.7">
55
<BuildAction
66
parallelizeBuildables = "YES"
77
buildImplicitDependencies = "YES">
8+
<PreActions>
9+
<ExecutionAction
10+
ActionType = "Xcode.IDEStandardExecutionActionsCore.ExecutionActionType.ShellScriptAction">
11+
<ActionContent
12+
title = "Run Script"
13+
scriptText = "export PATH=/usr/local/bin:$PATH&#10;cd &quot;$WORKSPACE_PATH&quot;/../../../IOS-BLE-Library/&#10;&#10;python3 code_gen/code_gen.py Sources&#10;">
14+
</ActionContent>
15+
</ExecutionAction>
16+
</PreActions>
817
<BuildActionEntries>
918
<BuildActionEntry
1019
buildForTesting = "YES"
@@ -20,54 +29,14 @@
2029
ReferencedContainer = "container:">
2130
</BuildableReference>
2231
</BuildActionEntry>
23-
<BuildActionEntry
24-
buildForTesting = "YES"
25-
buildForRunning = "NO"
26-
buildForProfiling = "NO"
27-
buildForArchiving = "NO"
28-
buildForAnalyzing = "YES">
29-
<BuildableReference
30-
BuildableIdentifier = "primary"
31-
BlueprintIdentifier = "iOS-BLE-LibraryTests"
32-
BuildableName = "iOS-BLE-LibraryTests"
33-
BlueprintName = "iOS-BLE-LibraryTests"
34-
ReferencedContainer = "container:">
35-
</BuildableReference>
36-
</BuildActionEntry>
37-
<BuildActionEntry
38-
buildForTesting = "YES"
39-
buildForRunning = "YES"
40-
buildForProfiling = "YES"
41-
buildForArchiving = "YES"
42-
buildForAnalyzing = "YES">
43-
<BuildableReference
44-
BuildableIdentifier = "primary"
45-
BlueprintIdentifier = "CoreBluetoothMock-Collection"
46-
BuildableName = "CoreBluetoothMock-Collection"
47-
BlueprintName = "CoreBluetoothMock-Collection"
48-
ReferencedContainer = "container:../CoreBluetoothMock-Collection">
49-
</BuildableReference>
50-
</BuildActionEntry>
5132
</BuildActionEntries>
5233
</BuildAction>
5334
<TestAction
5435
buildConfiguration = "Debug"
5536
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
5637
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
5738
shouldUseLaunchSchemeArgsEnv = "YES"
58-
codeCoverageEnabled = "YES"
59-
onlyGenerateCoverageForSpecifiedTargets = "YES">
60-
<CodeCoverageTargets>
61-
<BuildableReference
62-
BuildableIdentifier = "primary"
63-
BlueprintIdentifier = "iOS-BLE-Library"
64-
BuildableName = "iOS-BLE-Library"
65-
BlueprintName = "iOS-BLE-Library"
66-
ReferencedContainer = "container:">
67-
</BuildableReference>
68-
</CodeCoverageTargets>
69-
<Testables>
70-
</Testables>
39+
shouldAutocreateTestPlan = "YES">
7140
</TestAction>
7241
<LaunchAction
7342
buildConfiguration = "Debug"
@@ -79,12 +48,6 @@
7948
debugDocumentVersioning = "YES"
8049
debugServiceExtension = "internal"
8150
allowLocationSimulation = "YES">
82-
<CommandLineArguments>
83-
<CommandLineArgument
84-
argument = "-Xswiftc MOCK"
85-
isEnabled = "YES">
86-
</CommandLineArgument>
87-
</CommandLineArguments>
8851
</LaunchAction>
8952
<ProfileAction
9053
buildConfiguration = "Release"

README.md

+5-10
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,8 @@ pod 'iOS-BLE-Library-Mock', '~> 0.1.3'
6464

6565
As of this writing, we are not recommending this library for external use. It is used by both our Private and Public / Open-Source apps, hence the need to make it public as well. But for now we haven't settled on the API - we're still learning from all of Apple's new technologies such as Actors and Async / Await, therefore, it is likely big changes might be required as we move forward.
6666

67-
# TBD
68-
* Documentation
69-
* It will be added but the API is copying the CoreBluetooth API, so it should be easy to understand.
70-
* Examples
71-
* Currently examples can be found in iOS-nRF-Toolbox in the [develop](https://github.com/NordicSemiconductor/IOS-nRF-Toolbox/tree/develop) branch.
72-
* Unit Tests
73-
* Create two versions of the library:
74-
* CoreBluetooth API compatible
75-
* [CoreBluetoothMock](https://github.com/NordicSemiconductor/IOS-CoreBluetooth-Mock) API compatible
76-
* Currently the library is using the CoreBluetoothMock API. It can be not compatible with other libraries that relies on the CoreBluetooth API.
67+
# Documentation & Examples
68+
Please check the [Documentation Page](https://nordicsemiconductor.github.io/IOS-BLE-Library/documentation/ios_ble_library/) to start using the library.
69+
70+
Also you can check [iOS-nRF-Toolbox](https://github.com/NordicSemiconductor/IOS-nRF-Toolbox/tree/develop) to find more examples.
71+

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)