diff --git a/Sources/iOS-BLE-Library-Mock/CentralManager/CentralManager.swift b/Sources/iOS-BLE-Library-Mock/CentralManager/CentralManager.swift index 23f3e1a..87dd282 100644 --- a/Sources/iOS-BLE-Library-Mock/CentralManager/CentralManager.swift +++ b/Sources/iOS-BLE-Library-Mock/CentralManager/CentralManager.swift @@ -109,6 +109,26 @@ extension CentralManager { /// If the peripheral was disconnected successfully, the publisher finishes without error. /// If the connection was unsuccessful or disconnection returns an error (e.g., peripheral disconnected unexpectedly), /// the publisher finishes with an error. + /// + /// Use ``CentralManager/connect(_:options:)`` to connect to a peripheral. + /// The returned publisher will emit the connected peripheral or an error if the connection fails. + /// The publisher will not complete until the peripheral is disconnected. + /// If the connection fails, or the peripheral is unexpectedly disconnected, the publisher will fail with an error. + /// + /// ```swift + /// centralManager.connect(peripheral) + /// .sink { completion in + /// switch completion { + /// case .finished: + /// print("Peripheral disconnected successfully") + /// case .failure(let error): + /// print("Error: \(error)") + /// } + /// } receiveValue: { peripheral in + /// print("Peripheral connected: \(peripheral)") + /// } + /// .store(in: &cancellables) + /// ``` public func connect(_ peripheral: CBPeripheral, options: [String: Any]? = nil) -> AnyPublisher { diff --git a/Sources/iOS-BLE-Library-Mock/Documentation.docc/CentralManager/CentralManager.md b/Sources/iOS-BLE-Library-Mock/Documentation.docc/CentralManager/CentralManager.md index 19e34cc..5a74a87 100644 --- a/Sources/iOS-BLE-Library-Mock/Documentation.docc/CentralManager/CentralManager.md +++ b/Sources/iOS-BLE-Library-Mock/Documentation.docc/CentralManager/CentralManager.md @@ -2,37 +2,12 @@ ### Create a Central Manager -Since it's not recommended to override the `CBCentralManager`'s methods, ``CentralManager`` is merely a wrapper around `CBCentralManager` with an instance of it inside. +``CentralManager`` is merely a wrapper around `CBCentralManager` with an instance of it inside. -The new instance of `CBCentralManager` can be created during initialization using ``init(centralManagerDelegate:queue:)``, or an existing instance can be passed using ``init(centralManager:)``. +The new instance of `CBCentralManager` can be created during initialization using ``init(centralManagerDelegate:queue:options:)``, or an existing instance can be passed using ``init(centralManager:)``. If you pass a central manager inside ``init(centralManager:)``, it should already have a delegate set. The delegate should be an instance of ``ReactiveCentralManagerDelegate``; otherwise, an error will be thrown. -### Connection - -Use ``CentralManager/connect(_:options:)`` to connect to a peripheral. -The returned publisher will emit the connected peripheral or an error if the connection fails. -The publisher will not complete until the peripheral is disconnected. -If the connection fails, or the peripheral is unexpectedly disconnected, the publisher will fail with an error. - -> The publisher returned by ``CentralManager/connect(_:options:)`` is a `ConnectablePublisher`. Therefore, you need to call `connect()` or `autoconnect()` to initiate the connection process. - -```swift -centralManager.connect(peripheral) - .autoconnect() - .sink { completion in - switch completion { - case .finished: - print("Peripheral disconnected successfully") - case .failure(let error): - print("Error: \(error)") - } - } receiveValue: { peripheral in - print("Peripheral connected: \(peripheral)") - } - .store(in: &cancellables) -``` - ### Channels Channels are used to pass through data from the `CBCentralManagerDelegate` methods. diff --git a/Sources/iOS-BLE-Library-Mock/Documentation.docc/CentralManager/CentralManager/connect.md b/Sources/iOS-BLE-Library-Mock/Documentation.docc/CentralManager/CentralManager/connect.md new file mode 100644 index 0000000..fdaa466 --- /dev/null +++ b/Sources/iOS-BLE-Library-Mock/Documentation.docc/CentralManager/CentralManager/connect.md @@ -0,0 +1,7 @@ +# ``iOS_BLE_Library/CentralManager/connect(_:options:)`` + +## See Also + +- ``CentralManager/connectedPeripheralChannel`` +- ``CentralManager/disconnectedPeripheralsChannel`` + diff --git a/Sources/iOS-BLE-Library/CentralManager/CentralManager.swift b/Sources/iOS-BLE-Library/CentralManager/CentralManager.swift index dfc0379..98938de 100644 --- a/Sources/iOS-BLE-Library/CentralManager/CentralManager.swift +++ b/Sources/iOS-BLE-Library/CentralManager/CentralManager.swift @@ -122,6 +122,26 @@ extension CentralManager { /// If the peripheral was disconnected successfully, the publisher finishes without error. /// If the connection was unsuccessful or disconnection returns an error (e.g., peripheral disconnected unexpectedly), /// the publisher finishes with an error. + /// + /// Use ``CentralManager/connect(_:options:)`` to connect to a peripheral. + /// The returned publisher will emit the connected peripheral or an error if the connection fails. + /// The publisher will not complete until the peripheral is disconnected. + /// If the connection fails, or the peripheral is unexpectedly disconnected, the publisher will fail with an error. + /// + /// ```swift + /// centralManager.connect(peripheral) + /// .sink { completion in + /// switch completion { + /// case .finished: + /// print("Peripheral disconnected successfully") + /// case .failure(let error): + /// print("Error: \(error)") + /// } + /// } receiveValue: { peripheral in + /// print("Peripheral connected: \(peripheral)") + /// } + /// .store(in: &cancellables) + /// ``` public func connect(_ peripheral: CBPeripheral, options: [String: Any]? = nil) -> AnyPublisher { diff --git a/Sources/iOS-BLE-Library/Documentation.docc/CentralManager/CentralManager.md b/Sources/iOS-BLE-Library/Documentation.docc/CentralManager/CentralManager.md index 19e34cc..5a74a87 100644 --- a/Sources/iOS-BLE-Library/Documentation.docc/CentralManager/CentralManager.md +++ b/Sources/iOS-BLE-Library/Documentation.docc/CentralManager/CentralManager.md @@ -2,37 +2,12 @@ ### Create a Central Manager -Since it's not recommended to override the `CBCentralManager`'s methods, ``CentralManager`` is merely a wrapper around `CBCentralManager` with an instance of it inside. +``CentralManager`` is merely a wrapper around `CBCentralManager` with an instance of it inside. -The new instance of `CBCentralManager` can be created during initialization using ``init(centralManagerDelegate:queue:)``, or an existing instance can be passed using ``init(centralManager:)``. +The new instance of `CBCentralManager` can be created during initialization using ``init(centralManagerDelegate:queue:options:)``, or an existing instance can be passed using ``init(centralManager:)``. If you pass a central manager inside ``init(centralManager:)``, it should already have a delegate set. The delegate should be an instance of ``ReactiveCentralManagerDelegate``; otherwise, an error will be thrown. -### Connection - -Use ``CentralManager/connect(_:options:)`` to connect to a peripheral. -The returned publisher will emit the connected peripheral or an error if the connection fails. -The publisher will not complete until the peripheral is disconnected. -If the connection fails, or the peripheral is unexpectedly disconnected, the publisher will fail with an error. - -> The publisher returned by ``CentralManager/connect(_:options:)`` is a `ConnectablePublisher`. Therefore, you need to call `connect()` or `autoconnect()` to initiate the connection process. - -```swift -centralManager.connect(peripheral) - .autoconnect() - .sink { completion in - switch completion { - case .finished: - print("Peripheral disconnected successfully") - case .failure(let error): - print("Error: \(error)") - } - } receiveValue: { peripheral in - print("Peripheral connected: \(peripheral)") - } - .store(in: &cancellables) -``` - ### Channels Channels are used to pass through data from the `CBCentralManagerDelegate` methods. diff --git a/Sources/iOS-BLE-Library/Documentation.docc/CentralManager/CentralManager/connect.md b/Sources/iOS-BLE-Library/Documentation.docc/CentralManager/CentralManager/connect.md new file mode 100644 index 0000000..fdaa466 --- /dev/null +++ b/Sources/iOS-BLE-Library/Documentation.docc/CentralManager/CentralManager/connect.md @@ -0,0 +1,7 @@ +# ``iOS_BLE_Library/CentralManager/connect(_:options:)`` + +## See Also + +- ``CentralManager/connectedPeripheralChannel`` +- ``CentralManager/disconnectedPeripheralsChannel`` +