-
Notifications
You must be signed in to change notification settings - Fork 374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added initial state improvement & a minor fix for BluetoothState methods. #371
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,9 @@ import RxSwift | |
/// advertise, to publish L2CAP channels and more. | ||
/// You can start using this class by adding services and starting advertising. | ||
/// Before calling any public `PeripheralManager`'s functions you should make sure that Bluetooth is turned on and powered on. It can be done | ||
/// by `observeState()`, observing it's value and then chaining it with `add(_:)` and `startAdvertising(_:)`: | ||
/// by `observeStateWithInitialValue()`, observing it's value and then chaining it with `add(_:)` and `startAdvertising(_:)`: | ||
/// ``` | ||
/// let disposable = centralManager.observeState | ||
/// .startWith(centralManager.state) | ||
/// let disposable = centralManager.observeStateWithInitialValue() | ||
/// .filter { $0 == .poweredOn } | ||
/// .take(1) | ||
/// .flatMap { centralManager.add(myService) } | ||
|
@@ -69,13 +68,25 @@ public class PeripheralManager: ManagerType { | |
// MARK: State | ||
|
||
public var state: BluetoothState { | ||
return BluetoothState(rawValue: manager.state.rawValue) ?? .unsupported | ||
return BluetoothState(rawValue: manager.state.rawValue) ?? .unknown | ||
} | ||
|
||
public func observeState() -> Observable<BluetoothState> { | ||
return self.delegateWrapper.didUpdateState.asObservable() | ||
} | ||
|
||
public func observeStateWithInitialValue() -> Observable<BluetoothState> { | ||
return Observable.deferred { [weak self] in | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather add a new method which will return also current state than change current implementation. This will require less changes for users who already use our library. Can you create create new method for observing state and put there you code? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done :). Let me know what you think. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ping :D |
||
guard let self = self else { | ||
RxBluetoothKitLog.w("observeState - PeripheralManager deallocated") | ||
return .never() | ||
} | ||
|
||
return self.delegateWrapper.didUpdateState.asObservable() | ||
.startWith(self.state) | ||
} | ||
} | ||
|
||
// MARK: Advertising | ||
|
||
/// Starts peripheral advertising on subscription. It create inifinite observable | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Thanks for suggesting this changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.