Skip to content

Commit fe71a25

Browse files
authored
Merge branch 'master' into master
2 parents 9b24ad4 + 7c48869 commit fe71a25

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

Source/CBCentralManagerDelegateWrapper.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class CBCentralManagerDelegateWrapper: NSObject, CBCentralManagerDelegate {
1010
let didConnectPeripheral = PublishSubject<CBPeripheral>()
1111
let didFailToConnectPeripheral = PublishSubject<(CBPeripheral, Error?)>()
1212
let didDisconnectPeripheral = PublishSubject<(CBPeripheral, Error?)>()
13+
let didUpdateANCSAuthorizationForPeripheral = PublishSubject<(CBPeripheral)>()
1314

1415
func centralManagerDidUpdateState(_ central: CBCentralManager) {
1516
guard let bleState = BluetoothState(rawValue: central.state.rawValue) else { return }
@@ -59,4 +60,16 @@ class CBCentralManagerDelegateWrapper: NSObject, CBCentralManagerDelegate {
5960
""")
6061
didDisconnectPeripheral.onNext((peripheral, error))
6162
}
63+
64+
#if !os(macOS)
65+
@available(iOS 13.0, watchOS 6.0, tvOS 13.0, *)
66+
func centralManager(_ central: CBCentralManager,
67+
didUpdateANCSAuthorizationFor peripheral: CBPeripheral) {
68+
RxBluetoothKitLog.d("""
69+
\(central.logDescription) didUpdateANCSAuthorizationFor
70+
(peripheral: \(peripheral.logDescription)
71+
""")
72+
didUpdateANCSAuthorizationForPeripheral.onNext(peripheral)
73+
}
74+
#endif
6275
}

Source/CentralManager.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,27 @@ public class CentralManager: ManagerType {
297297
}
298298
}
299299

300+
// MARK: ANCS
301+
302+
/// Emits boolean values according to ancsAuthorized property on a CBPeripheral.
303+
///
304+
/// - parameter peripheral: `Peripheral` which is observed for ancsAuthorized chances.
305+
/// - returns: Observable which emits next events when `ancsAuthorized` property changes on a peripheral.
306+
#if !os(macOS)
307+
@available(iOS 13.0, watchOS 6.0, tvOS 13.0, *)
308+
public func observeANCSAuthorized(for peripheral: Peripheral) -> Observable<Bool> {
309+
let observable = delegateWrapper.didUpdateANCSAuthorizationForPeripheral
310+
.asObservable()
311+
.filter { $0 == peripheral.peripheral }
312+
// ancsAuthorized is a Bool by default, but the testing framework
313+
// will use Bool! instead. In order to support that we are converting
314+
// to optional and unwrapping the value.
315+
.map { ($0.ancsAuthorized as Bool?)! }
316+
317+
return ensure(.poweredOn, observable: observable)
318+
}
319+
#endif
320+
300321
// MARK: Internal functions
301322

302323
/// Ensure that specified `peripheral` is connected during subscription.

Tests/Autogenerated/Mock.generated.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,7 @@ class CBCentralManagerDelegateWrapperMock: NSObject , CBCentralManagerDelegate {
574574
var didConnectPeripheral = PublishSubject<CBPeripheralMock>()
575575
var didFailToConnectPeripheral = PublishSubject<(CBPeripheralMock, Error?)>()
576576
var didDisconnectPeripheral = PublishSubject<(CBPeripheralMock, Error?)>()
577+
var didUpdateANCSAuthorizationForPeripheral = PublishSubject<(CBPeripheralMock)>()
577578

578579
override init() {
579580
}
@@ -595,6 +596,11 @@ class CBCentralManagerDelegateWrapperMock: NSObject , CBCentralManagerDelegate {
595596

596597
func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: Error?) {
597598
}
599+
600+
#if !os(macOS)
601+
func centralManager(_ central: CBCentralManager, didUpdateANCSAuthorizationFor peripheral: CBPeripheral) {
602+
}
603+
#endif
598604
}
599605
class CBPeripheralManagerDelegateWrapperMock: NSObject , CBPeripheralManagerDelegate {
600606
var didUpdateState = PublishSubject<BluetoothState>()

Tests/Autogenerated/_CentralManager.generated.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,27 @@ class _CentralManager: _ManagerType {
298298
}
299299
}
300300

301+
// MARK: ANCS
302+
303+
/// Emits boolean values according to ancsAuthorized property on a CBPeripheralMock.
304+
///
305+
/// - parameter peripheral: `_Peripheral` which is observed for ancsAuthorized chances.
306+
/// - returns: Observable which emits next events when `ancsAuthorized` property changes on a peripheral.
307+
#if !os(macOS)
308+
@available(iOS 13.0, watchOS 6.0, tvOS 13.0, *)
309+
func observeANCSAuthorized(for peripheral: _Peripheral) -> Observable<Bool> {
310+
let observable = delegateWrapper.didUpdateANCSAuthorizationForPeripheral
311+
.asObservable()
312+
.filter { $0 == peripheral.peripheral }
313+
// ancsAuthorized is a Bool by default, but the testing framework
314+
// will use Bool! instead. In order to support that we are converting
315+
// to optional and unwrapping the value.
316+
.map { ($0.ancsAuthorized as Bool?)! }
317+
318+
return ensure(.poweredOn, observable: observable)
319+
}
320+
#endif
321+
301322
// MARK: Internal functions
302323

303324
/// Ensure that specified `peripheral` is connected during subscription.

0 commit comments

Comments
 (0)