Skip to content

Commit 5a528a7

Browse files
author
Nick Kibysh
committed
revert: f15e2bb is redundant.
- Return Data Extension and make it internal to not to conflict with other libraries.
2 parents d7bec00 + 514de11 commit 5a528a7

19 files changed

+973
-891
lines changed

Gemfile.lock

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
CFPropertyList (3.0.7)
5+
base64
6+
nkf
7+
rexml
8+
activesupport (7.1.3)
9+
base64
10+
bigdecimal
11+
concurrent-ruby (~> 1.0, >= 1.0.2)
12+
connection_pool (>= 2.2.5)
13+
drb
14+
i18n (>= 1.6, < 2)
15+
minitest (>= 5.1)
16+
mutex_m
17+
tzinfo (~> 2.0)
18+
addressable (2.8.7)
19+
public_suffix (>= 2.0.2, < 7.0)
20+
algoliasearch (1.27.5)
21+
httpclient (~> 2.8, >= 2.8.3)
22+
json (>= 1.5.1)
23+
atomos (0.1.3)
24+
base64 (0.2.0)
25+
bigdecimal (3.1.6)
26+
claide (1.1.0)
27+
cocoapods (1.15.2)
28+
addressable (~> 2.8)
29+
claide (>= 1.0.2, < 2.0)
30+
cocoapods-core (= 1.15.2)
31+
cocoapods-deintegrate (>= 1.0.3, < 2.0)
32+
cocoapods-downloader (>= 2.1, < 3.0)
33+
cocoapods-plugins (>= 1.0.0, < 2.0)
34+
cocoapods-search (>= 1.0.0, < 2.0)
35+
cocoapods-trunk (>= 1.6.0, < 2.0)
36+
cocoapods-try (>= 1.1.0, < 2.0)
37+
colored2 (~> 3.1)
38+
escape (~> 0.0.4)
39+
fourflusher (>= 2.3.0, < 3.0)
40+
gh_inspector (~> 1.0)
41+
molinillo (~> 0.8.0)
42+
nap (~> 1.0)
43+
ruby-macho (>= 2.3.0, < 3.0)
44+
xcodeproj (>= 1.23.0, < 2.0)
45+
cocoapods-core (1.15.2)
46+
activesupport (>= 5.0, < 8)
47+
addressable (~> 2.8)
48+
algoliasearch (~> 1.0)
49+
concurrent-ruby (~> 1.1)
50+
fuzzy_match (~> 2.0.4)
51+
nap (~> 1.0)
52+
netrc (~> 0.11)
53+
public_suffix (~> 4.0)
54+
typhoeus (~> 1.0)
55+
cocoapods-deintegrate (1.0.5)
56+
cocoapods-downloader (2.1)
57+
cocoapods-plugins (1.0.0)
58+
nap
59+
cocoapods-search (1.0.1)
60+
cocoapods-trunk (1.6.0)
61+
nap (>= 0.8, < 2.0)
62+
netrc (~> 0.11)
63+
cocoapods-try (1.2.0)
64+
colored2 (3.1.2)
65+
concurrent-ruby (1.2.3)
66+
connection_pool (2.4.1)
67+
drb (2.2.0)
68+
ruby2_keywords
69+
escape (0.0.4)
70+
ethon (0.16.0)
71+
ffi (>= 1.15.0)
72+
ffi (1.16.3)
73+
fourflusher (2.3.1)
74+
fuzzy_match (2.0.4)
75+
gh_inspector (1.1.3)
76+
httpclient (2.8.3)
77+
i18n (1.14.1)
78+
concurrent-ruby (~> 1.0)
79+
json (2.9.1)
80+
minitest (5.22.2)
81+
molinillo (0.8.0)
82+
mutex_m (0.2.0)
83+
nanaimo (0.4.0)
84+
nap (1.1.0)
85+
netrc (0.11.0)
86+
nkf (0.2.0)
87+
public_suffix (4.0.7)
88+
rexml (3.4.0)
89+
ruby-macho (2.5.1)
90+
ruby2_keywords (0.0.5)
91+
typhoeus (1.4.1)
92+
ethon (>= 0.9.0)
93+
tzinfo (2.0.6)
94+
concurrent-ruby (~> 1.0)
95+
xcodeproj (1.27.0)
96+
CFPropertyList (>= 2.3.3, < 4.0)
97+
atomos (~> 0.1.3)
98+
claide (>= 1.0.2, < 2.0)
99+
colored2 (~> 3.1)
100+
nanaimo (~> 0.4.0)
101+
rexml (>= 3.3.6, < 4.0)
102+
103+
PLATFORMS
104+
arm64-darwin-23
105+
106+
DEPENDENCIES
107+
activesupport (~> 7.0, >= 7.0.8)
108+
cocoapods
109+
110+
BUNDLED WITH
111+
2.3.10

Package.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import PackageDescription
44
let package = Package(
55
name: "iOS-BLE-Library",
66
platforms: [
7-
.iOS(.v15),
8-
.macOS(.v12)
7+
.iOS(.v13),
8+
.macOS(.v10_15),
9+
.watchOS(.v6)
910
],
1011
products: [
1112
.library(name: "iOS-BLE-Library", targets: ["iOS-BLE-Library"]),
@@ -15,7 +16,6 @@ let package = Package(
1516
.package(url: "https://github.com/NordicSemiconductor/IOS-CoreBluetooth-Mock.git", from: "0.17.0"),
1617
.package(url: "https://github.com/NickKibish/CoreBluetoothMock-Collection.git", from: "1.0.0"),
1718
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
18-
.package(url: "https://github.com/NordicPlayground/IOS-Common-Libraries", branch: "main"),
1919
],
2020
targets: [
2121
.target(name: "iOS-BLE-Library"),

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

+32-39
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,16 +218,14 @@ 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
/// - Parameters:
229225
/// - services: The services to scan for.
230226
/// - options: A dictionary to customize the scan, such as specifying whether duplicate results should be reported.
231227
/// - Returns: A publisher that emits scan results or an error.
232-
public func scanForPeripherals(
233-
withServices services: [CBUUID]?, options: [String: Any]? = nil
234-
)
228+
public func scanForPeripherals(withServices services: [CBUUID]?, options: [String: Any]? = nil)
235229
-> AnyPublisher<ScanResult, Error>
236230
{
237231
stopScan()
@@ -256,11 +250,10 @@ extension CentralManager {
256250
return e
257251
}
258252
.bluetooth {
259-
self.centralManager.scanForPeripherals(
260-
withServices: services, options: options)
253+
self.centralManager.scanForPeripherals(withServices: services, options: options)
261254
}
262-
.autoconnect()
263-
.eraseToAnyPublisher()
255+
.autoconnect()
256+
.eraseToAnyPublisher()
264257
}
265258

266259
/// Stops an ongoing scan for peripherals.

0 commit comments

Comments
 (0)