-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/doc_getting_started' into develop
- Loading branch information
Showing
9 changed files
with
222 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
Sources/iOS-BLE-Library/Documentation.docc/CentralManager/CentralManager.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# ``iOS_BLE_Library/CentralManager`` | ||
|
||
### 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. | ||
|
||
The new instance of `CBCentralManager` can be created during initialization using ``init(centralManagerDelegate:queue:)``, 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. | ||
You can consider them as a reactive version of the `CBCentralManagerDelegate` methods. | ||
|
||
In most cases, you will not need to use them directly, as `centralManager`'s methods return proper publishers. However, if you need to handle the data differently (e.g., log all the events), you can subscribe to the channels directly. | ||
|
||
All channels have `Never` as their failure type because they never fail. Some channels, like `CentralManager/connectedPeripheralChannel` or `CentralManager/disconnectedPeripheralsChannel`, send tuples with the peripheral and the error, allowing you to handle errors if needed. Despite this, the failure type remains `Never`, so it will not complete even if an error occurs during the connection or disconnection of the peripheral. | ||
|
||
```swift | ||
centralManager.connectedPeripheralChannel | ||
.sink { peripheral, error in | ||
if let error = error { | ||
print("Error: \(error)") | ||
} else { | ||
print("New peripheral connected: \(peripheral)" | ||
} | ||
} | ||
.store(in: &cancellables) | ||
``` | ||
|
||
## Topics | ||
|
||
### Initializers | ||
|
||
- ``init(centralManagerDelegate:queue:)`` | ||
- ``init(centralManager:)`` | ||
|
||
### Instance Properties | ||
|
||
- ``centralManager`` | ||
- ``centralManagerDelegate`` | ||
|
||
### Scan | ||
|
||
- ``scanForPeripherals(withServices:)`` | ||
- ``stopScan()`` | ||
- ``retrievePeripherals(withIdentifiers:)`` | ||
|
||
### Connection | ||
|
||
- ``connect(_:options:)`` | ||
- ``cancelPeripheralConnection(_:)`` | ||
- ``retrieveConnectedPeripherals(withServices:)`` | ||
|
||
### Channels | ||
|
||
- ``stateChannel`` | ||
- ``isScanningChannel`` | ||
- ``scanResultsChannel`` | ||
- ``connectedPeripheralChannel`` | ||
- ``disconnectedPeripheralsChannel`` |
16 changes: 16 additions & 0 deletions
16
...BLE-Library/Documentation.docc/CentralManager/ReactiveCentralManagerDelegate.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# ``iOS_BLE_Library/ReactiveCentralManagerDelegate`` | ||
|
||
Implementation of the `CBCentralManagerDelegate`. | ||
|
||
`ReactiveCentralManagerDelegate` is a class that implements the `CBCentralManagerDelegate` and is an essential part of the ``CentralManager`` class. | ||
|
||
It brings a reactive programming approach, utilizing Combine publishers to seamlessly handle Bluetooth events and data. | ||
This class allows to monitor and respond to events such as peripheral connection, disconnection, and scanning for peripherals. | ||
|
||
It has all needed publishers that are used for handling Bluetooth events and data. | ||
|
||
## Override | ||
|
||
It's possible to override the default implementation of the `ReactiveCentralManagerDelegate` by creating a new class that inherits from `ReactiveCentralManagerDelegate` and overriding the needed methods. | ||
|
||
However, it's important to call the `super` implementation of the method, otherwise it will break the `CentralManager` functionality. |
19 changes: 19 additions & 0 deletions
19
Sources/iOS-BLE-Library/Documentation.docc/Documentation.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# ``iOS_BLE_Library`` | ||
|
||
This library is a wrapper around the CoreBluetooth framework which provides a modern async API based on Combine Framework. | ||
|
||
The library has been designed to have a simple API similar to the one provided by the CoreBluetooth framework. | ||
So if you are familiar with the CoreBluetooth framework, you will be able to use this library without any problem. | ||
|
||
## Topics | ||
|
||
### Central Manager | ||
- ``CentralManager`` | ||
- ``ReactiveCentralManagerDelegate`` | ||
|
||
### Peripheral | ||
- ``Peripheral`` | ||
- ``ReactivePeripheralDelegate`` | ||
|
||
### Essentials | ||
- ``iOS_BLE_Library/Combine/Publishers/BluetoothPublisher`` |
5 changes: 5 additions & 0 deletions
5
Sources/iOS-BLE-Library/Documentation.docc/Peripheral/Peripheral.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
``iOS_BLE_Library/Peripheral`` | ||
|
||
### Create a Peripheral | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.