Skip to content

Commit ef1f1a4

Browse files
committedOct 2, 2020
Added optional CBCentralManager parameter to CentralManager init. Added optional CBPeripheralManager parameter to PeripheralManager init.
1 parent ba162fb commit ef1f1a4

8 files changed

+42
-15
lines changed
 

‎RxBluetoothKit.xcodeproj/project.pbxproj

+3-3
Original file line numberDiff line numberDiff line change
@@ -410,12 +410,12 @@
410410
A10F299A1CDCD73A00593284 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nimble.framework; path = Carthage/Build/iOS/Nimble.framework; sourceTree = SOURCE_ROOT; };
411411
A1299C0C1CBE3DEE005DEA5B /* AdvertisementData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AdvertisementData.swift; sourceTree = "<group>"; };
412412
A1299C0D1CBE3DEE005DEA5B /* BluetoothError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BluetoothError.swift; sourceTree = "<group>"; };
413-
A1299C0E1CBE3DEE005DEA5B /* CentralManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = CentralManager.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
413+
A1299C0E1CBE3DEE005DEA5B /* CentralManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = CentralManager.swift; sourceTree = "<group>"; };
414414
A1299C0F1CBE3DEE005DEA5B /* Boxes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Boxes.swift; sourceTree = "<group>"; };
415-
A1299C101CBE3DEE005DEA5B /* Characteristic.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = Characteristic.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
415+
A1299C101CBE3DEE005DEA5B /* Characteristic.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = Characteristic.swift; sourceTree = "<group>"; };
416416
A1299C121CBE3DEE005DEA5B /* Descriptor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = Descriptor.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
417417
A1299C131CBE3DEE005DEA5B /* Observable+Absorb.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = "Observable+Absorb.swift"; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
418-
A1299C161CBE3DEE005DEA5B /* Peripheral.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = Peripheral.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
418+
A1299C161CBE3DEE005DEA5B /* Peripheral.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = Peripheral.swift; sourceTree = "<group>"; };
419419
A1299C211CBE3DEE005DEA5B /* ScannedPeripheral.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScannedPeripheral.swift; sourceTree = "<group>"; };
420420
A1299C231CBE3DEE005DEA5B /* Service.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Service.swift; sourceTree = "<group>"; };
421421
A1299C241CBE3DEE005DEA5B /* Unimplemented.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Unimplemented.swift; sourceTree = "<group>"; };

‎Source/CentralManager+RestoredState.swift

+6-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ extension CentralManager {
1515
@available(*, deprecated, renamed: "CentralManager.init(queue:options:onWillRestoreCentralManagerState:)")
1616
public convenience init(queue: DispatchQueue = .main,
1717
options: [String: AnyObject]? = nil,
18+
cbCentralManager: CBCentralManager? = nil,
1819
onWillRestoreState: OnWillRestoreState? = nil) {
19-
self.init(queue: queue, options: options)
20+
self.init(queue: queue, options: options, cbCentralManager: cbCentralManager)
2021
if let onWillRestoreState = onWillRestoreState {
2122
listenOnWillRestoreState(onWillRestoreState)
2223
}
@@ -29,13 +30,16 @@ extension CentralManager {
2930
/// and all operations and events are executed and received on main thread.
3031
/// - parameter options: An optional dictionary containing initialization options for a central manager.
3132
/// For more info about it please refer to [Central Manager initialization options](https://developer.apple.com/library/ios/documentation/CoreBluetooth/Reference/CBCentralManager_Class/index.html)
33+
/// - parameter cbCentralManager: Optional instance of `CBCentralManager` to be used as a `manager`.
34+
/// If you skip this parameter, there will be created an instance of `CBCentralManager` using given queue and options.
3235
/// - parameter onWillRestoreCentralManagerState: Closure called when state has been restored.
3336
///
3437
/// - seealso: `OnWillRestoreCentralManagerState`
3538
public convenience init(queue: DispatchQueue = .main,
3639
options: [String: AnyObject]? = nil,
40+
cbCentralManager: CBCentralManager? = nil,
3741
onWillRestoreCentralManagerState: OnWillRestoreCentralManagerState? = nil) {
38-
self.init(queue: queue, options: options)
42+
self.init(queue: queue, options: options, cbCentralManager: cbCentralManager)
3943
if let onWillRestoreCentralManagerState = onWillRestoreCentralManagerState {
4044
listenOnWillRestoreState(onWillRestoreCentralManagerState)
4145
}

‎Source/CentralManager.swift

+6-2
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,14 @@ public class CentralManager: ManagerType {
7070
/// - parameter queue: Queue on which bluetooth callbacks are received. By default main thread is used.
7171
/// - parameter options: An optional dictionary containing initialization options for a central manager.
7272
/// For more info about it please refer to [Central Manager initialization options](https://developer.apple.com/library/ios/documentation/CoreBluetooth/Reference/CBCentralManager_Class/index.html)
73+
/// - parameter cbCentralManager: Optional instance of `CBCentralManager` to be used as a `manager`. If you
74+
/// skip this parameter, there will be created an instance of `CBCentralManager` using given queue and options.
7375
public convenience init(queue: DispatchQueue = .main,
74-
options: [String: AnyObject]? = nil) {
76+
options: [String: AnyObject]? = nil,
77+
cbCentralManager: CBCentralManager? = nil) {
7578
let delegateWrapper = CBCentralManagerDelegateWrapper()
76-
let centralManager = CBCentralManager(delegate: delegateWrapper, queue: queue, options: options)
79+
let centralManager = cbCentralManager != nil ?
80+
cbCentralManager! : CBCentralManager(delegate: delegateWrapper, queue: queue, options: options)
7781
self.init(
7882
centralManager: centralManager,
7983
delegateWrapper: delegateWrapper,

‎Source/PeripheralManager+RestoredState.swift

+3
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@ extension PeripheralManager {
1616
/// and all operations and events are executed and received on main thread.
1717
/// - parameter options: An optional dictionary containing initialization options for a peripheral manager.
1818
/// For more info about it please refer to [Peripheral Manager initialization options](https://developer.apple.com/documentation/corebluetooth/cbperipheralmanager/peripheral_manager_initialization_options)
19+
/// - parameter cbPeripheralManager: Optional instance of `CBPeripheralManager` to be used as a `manager`. If you
20+
/// skip this parameter, there will be created an instance of `CBPeripheralManager` using given queue and options.
1921
/// - parameter onWillRestorePeripheralManagerState: Closure called when state has been restored.
2022
///
2123
/// - seealso: `RestoredState`
2224
public convenience init(queue: DispatchQueue = .main,
2325
options: [String: AnyObject]? = nil,
26+
cbPeripheralManager: CBPeripheralManager? = nil,
2427
onWillRestorePeripheralManagerState: OnWillRestorePeripheralManagerState? = nil) {
2528
self.init(queue: queue, options: options)
2629
if let onWillRestorePeripheralManagerState = onWillRestorePeripheralManagerState {

‎Source/PeripheralManager.swift

+6-2
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,15 @@ public class PeripheralManager: ManagerType {
4747
/// - parameter queue: Queue on which bluetooth callbacks are received. By default main thread is used.
4848
/// - parameter options: An optional dictionary containing initialization options for a peripheral manager.
4949
/// For more info about it please refer to [Peripheral Manager initialization options](https://developer.apple.com/documentation/corebluetooth/cbperipheralmanager/peripheral_manager_initialization_options)
50+
/// - parameter cbPeripheralManager: Optional instance of `CBPeripheralManager` to be used as a `manager`. If you
51+
/// skip this parameter, there will be created an instance of `CBPeripheralManager` using given queue and options.
5052
public convenience init(queue: DispatchQueue = .main,
51-
options: [String: AnyObject]? = nil) {
53+
options: [String: AnyObject]? = nil,
54+
cbPeripheralManager: CBPeripheralManager? = nil) {
5255
let delegateWrapper = CBPeripheralManagerDelegateWrapper()
5356
#if os(iOS) || os(macOS)
54-
let peripheralManager = CBPeripheralManager(delegate: delegateWrapper, queue: queue, options: options)
57+
let peripheralManager = cbPeripheralManager != nil ?
58+
cbPeripheralManager! : CBPeripheralManager(delegate: delegateWrapper, queue: queue, options: options)
5559
#else
5660
let peripheralManager = CBPeripheralManager()
5761
peripheralManager.delegate = delegateWrapper

‎Tests/Autogenerated/_CentralManager+RestoredState.generated.swift

+6-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ extension _CentralManager {
1616
@available(*, deprecated, renamed: "_CentralManager.init(queue:options:onWillRestoreCentralManagerState:)")
1717
convenience init(queue: DispatchQueue = .main,
1818
options: [String: AnyObject]? = nil,
19+
cbCentralManager: CBCentralManagerMock? = nil,
1920
onWillRestoreState: OnWillRestoreState? = nil) {
20-
self.init(queue: queue, options: options)
21+
self.init(queue: queue, options: options, cbCentralManager: cbCentralManager)
2122
if let onWillRestoreState = onWillRestoreState {
2223
listenOnWillRestoreState(onWillRestoreState)
2324
}
@@ -30,13 +31,16 @@ extension _CentralManager {
3031
/// and all operations and events are executed and received on main thread.
3132
/// - parameter options: An optional dictionary containing initialization options for a central manager.
3233
/// For more info about it please refer to [Central Manager initialization options](https://developer.apple.com/library/ios/documentation/CoreBluetooth/Reference/CBCentralManager_Class/index.html)
34+
/// - parameter cbCentralManager: Optional instance of `CBCentralManagerMock` to be used as a `manager`.
35+
/// If you skip this parameter, there will be created an instance of `CBCentralManagerMock` using given queue and options.
3336
/// - parameter onWillRestoreCentralManagerState: Closure called when state has been restored.
3437
///
3538
/// - seealso: `OnWillRestoreCentralManagerState`
3639
convenience init(queue: DispatchQueue = .main,
3740
options: [String: AnyObject]? = nil,
41+
cbCentralManager: CBCentralManagerMock? = nil,
3842
onWillRestoreCentralManagerState: OnWillRestoreCentralManagerState? = nil) {
39-
self.init(queue: queue, options: options)
43+
self.init(queue: queue, options: options, cbCentralManager: cbCentralManager)
4044
if let onWillRestoreCentralManagerState = onWillRestoreCentralManagerState {
4145
listenOnWillRestoreState(onWillRestoreCentralManagerState)
4246
}

‎Tests/Autogenerated/_CentralManager.generated.swift

+6-2
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,14 @@ class _CentralManager: _ManagerType {
7171
/// - parameter queue: Queue on which bluetooth callbacks are received. By default main thread is used.
7272
/// - parameter options: An optional dictionary containing initialization options for a central manager.
7373
/// For more info about it please refer to [Central Manager initialization options](https://developer.apple.com/library/ios/documentation/CoreBluetooth/Reference/CBCentralManager_Class/index.html)
74+
/// - parameter cbCentralManager: Optional instance of `CBCentralManagerMock` to be used as a `manager`. If you
75+
/// skip this parameter, there will be created an instance of `CBCentralManagerMock` using given queue and options.
7476
convenience init(queue: DispatchQueue = .main,
75-
options: [String: AnyObject]? = nil) {
77+
options: [String: AnyObject]? = nil,
78+
cbCentralManager: CBCentralManagerMock? = nil) {
7679
let delegateWrapper = CBCentralManagerDelegateWrapperMock()
77-
let centralManager = CBCentralManagerMock(delegate: delegateWrapper, queue: queue, options: options)
80+
let centralManager = cbCentralManager != nil ?
81+
cbCentralManager! : CBCentralManagerMock(delegate: delegateWrapper, queue: queue, options: options)
7882
self.init(
7983
centralManager: centralManager,
8084
delegateWrapper: delegateWrapper,

‎Tests/Autogenerated/_PeripheralManager.generated.swift

+6-2
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,15 @@ class _PeripheralManager: _ManagerType {
4848
/// - parameter queue: Queue on which bluetooth callbacks are received. By default main thread is used.
4949
/// - parameter options: An optional dictionary containing initialization options for a peripheral manager.
5050
/// For more info about it please refer to [_Peripheral Manager initialization options](https://developer.apple.com/documentation/corebluetooth/cbperipheralmanager/peripheral_manager_initialization_options)
51+
/// - parameter cbPeripheralManager: Optional instance of `CBPeripheralManagerMock` to be used as a `manager`. If you
52+
/// skip this parameter, there will be created an instance of `CBPeripheralManagerMock` using given queue and options.
5153
convenience init(queue: DispatchQueue = .main,
52-
options: [String: AnyObject]? = nil) {
54+
options: [String: AnyObject]? = nil,
55+
cbPeripheralManager: CBPeripheralManagerMock? = nil) {
5356
let delegateWrapper = CBPeripheralManagerDelegateWrapperMock()
5457
#if os(iOS) || os(macOS)
55-
let peripheralManager = CBPeripheralManagerMock(delegate: delegateWrapper, queue: queue, options: options)
58+
let peripheralManager = cbPeripheralManager != nil ?
59+
cbPeripheralManager! : CBPeripheralManagerMock(delegate: delegateWrapper, queue: queue, options: options)
5660
#else
5761
let peripheralManager = CBPeripheralManagerMock()
5862
peripheralManager.delegate = delegateWrapper

0 commit comments

Comments
 (0)
Please sign in to comment.