Skip to content

Commit 7c79ba3

Browse files
authored
Merge pull request #259 from Polidea/feature/guide_for_migrating_to_5
Added guide for migration to 5.x
2 parents 93ae1de + dac21e4 commit 7c79ba3

File tree

2 files changed

+130
-4
lines changed

2 files changed

+130
-4
lines changed

GUID_FOR_MIGRATING_TO_5.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# Guide for migrating to `RxBluetothKit` 5
2+
3+
### What has changed?
4+
5+
`RxBlutoothKit` starting from version 5.0.0 changes a lot in API. Here is a list of main changes that occured:
6+
7+
- `BluetoothManager` renamed to `CentralManager` - with this change we have unified naming with `CoreBluetooth`. This change also gives us possibility to add easily `PeripheralManager` support.
8+
- Changed returns from `Observable<>` to `Single` where applies.
9+
- Removed `BluetoothManager.listenOnRestoredState` and instead of this added new `CentralManager.init(queue: DispatchQueue, options: [String: AnyObject]?, onWillRestoreState: OnWillRestoreState?)` initializer
10+
- removed support for calling `CentralManager.scanForPeripherals` when scanning is ongoing. Before we were doing queuing or sharing of new call but we had numerous issues with such approach. From now on, if there is ongoing scan `Observable` will immediately finish with `BluettothError.scanInProgress` error.
11+
- `BluetoothManager.rx_state` renamed to `CentralManager.observeState`. In addition to it `CentralManager.observeState` is no more starting with current state value.
12+
- `BluetoothManager.connect` renamed to `CentralManager.establishConnection`. Removed `BluetoothManager.cancelPeripheralConnection` and `Peripheral.cancelConnection`. We have changed way of connecting to peripheral in more reactive way. `CentralManager.establishConnection` is now also canceling connection on it's dispose. Due to that chanes it is now not possible to call `CentralManager.establishConnection` on device that is already connected (the only exception of this behaviour is for devices that we get from state restoration).
13+
- `CentralManager.retrieveConnectedPeripherals` and `CentralManager.retrievePeripherals` are now returning `[Peripheral]` instead of `Observable<[Peripheral]>`.
14+
- `BluetoothManager.monitorConnection` renamed to `CentralManager.observeConnect`.
15+
- `BluetoothManager.monitorDisconnection` renamed to `CentralManager.observeDisconnect`.
16+
- all `Peripheral.monitorWrite` methods renamed to `Peripheral.observeWrite`.
17+
- all `Peripheral.monitorValueUpdate` methods renamed to `Peripheral.observeValueUpdate`.
18+
- `Peripheral.monitorNameUpdate` renamed to `Peripheral.observeNameUpdate`.
19+
- `Peripheral.monitorServicesModification` renamed to `Peripheral.observeServicesModification`.
20+
- `Peripheral.observeValueUpdateAndSetNotification` added, `Peripheral.setNotifyValue` and `Peripheral.setNotificationAndMonitorUpdates` removed. From now on is seting notificaiton on subscription and unseting it on disposing. In addition it is possible to set more observables for same characteristic - it will work in a way that dispose will only happen when there are no observables for characteristic.
21+
22+
23+
### Diffs on `README.md` file
24+
25+
```swift
26+
-let stateObservable = manager.rx_state
27+
+let stateObservable = manager.observeState()
28+
```
29+
30+
```swift
31+
-manager.rx_state
32+
+manager.observeState()
33+
+ .startWith(manager.state)
34+
.filter { $0 == .poweredOn }
35+
.timeout(3.0, scheduler)
36+
.take(1)
37+
- .flatMap { manager.scanForPeripherals(withServices: [serviceId]) }
38+
+ .flatMap { _ in manager.scanForPeripherals(withServices: [serviceId]) }
39+
```
40+
41+
```swift
42+
manager.scanForPeripherals(withServices: [serviceId]).take(1)
43+
- .flatMap { $0.peripheral.connect() }
44+
+ .flatMap { $0.peripheral.establishConnection() }
45+
.subscribe(onNext: { peripheral in
46+
print("Connected to: \(peripheral)")
47+
})
48+
```
49+
50+
```swift
51+
-peripheral.connect()
52+
- .flatMap { $0.discoverServices([serviceId]) }
53+
+peripheral.establishConnection()
54+
+ .flatMap { $0.discoverServices([serviceId]) }.asObservable()
55+
.flatMap { Observable.from($0) }
56+
```
57+
58+
```swift
59+
-peripheral.connect()
60+
- .flatMap { $0.discoverServices([serviceId]) }
61+
+peripheral.establishConnection()
62+
+ .flatMap { $0.discoverServices([serviceId]) }.asObservable()
63+
.flatMap { Observable.from($0) }
64+
- .flatMap { $0.discoverCharacteristics([characteristicId])}
65+
+ .flatMap { $0.discoverCharacteristics([characteristicId])}.asObservable()
66+
.flatMap { Observable.from($0) }
67+
```
68+
69+
```swift
70+
-peripheral.connect()
71+
- .flatMap { $0.discoverServices([serviceId]) }
72+
+peripheral.establishConnection()
73+
+ .flatMap { $0.discoverServices([serviceId]) }.asObservable()
74+
.flatMap { Observable.from($0) }
75+
- .flatMap { $0.discoverCharacteristics([characteristicId])}
76+
+ .flatMap { $0.discoverCharacteristics([characteristicId])}.asObservable()
77+
.flatMap { Observable.from($0) }
78+
```
79+
80+
```swift
81+
-characteristic.setNotificationAndMonitorUpdates()
82+
+let disposable = characteristic.observeValueUpdateAndSetNotification()
83+
.subscribe(onNext: {
84+
let newValue = $0.value
85+
})
86+
```
87+
88+
```swift
89+
-characteristic.setNotifyValue(false)
90+
- .subscribe(onNext: { characteristic in
91+
- //Notification are now disabled.
92+
- })
93+
+disposable.dispose()
94+
```
95+
96+
```swift
97+
-peripheral.connect()
98+
- .flatMap { Observable.from($0.discoverServices([serviceId])) }
99+
- .flatMap { Observable.from($0.discoverCharacteristics([characteristicId])}
100+
- .flatMap { $0.readValue }
101+
- .subscribe(onNext: {
102+
- let data = $0.value
103+
- })
104+
+peripheral.establishConnection()
105+
+ .flatMap { $0.discoverServices([serviceId]) }.asObservable()
106+
+ .flatMap { Observable.from($0) }
107+
+ .flatMap { $0.discoverCharacteristics([characteristicId])}.asObservable()
108+
+ .flatMap { Observable.from($0) }
109+
+ .flatMap { $0.readValue() }
110+
+ .subscribe(onNext: {
111+
+ let data = $0.value
112+
+ })
113+
```

README.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Provides nice API to work with, and makes your code more readable, reliable and
1010
* 3.0 version supports Swift 3.0 and 3.1
1111
* 5.0 version of the library supports Swift 3.2 and 4.0
1212

13+
#### Migrating to 5.x
14+
15+
If you are already using version below 5.x and want to upgrade [here](https://github.com/Polidea/RxBluetoothKit/blob/master/GUID_FOR_MIGRATING_TO_5.md) you will find guide for doing this.
1316

1417
## Documentation & Support
1518

@@ -317,11 +320,10 @@ Library supports **complex** Bluetooth error handling functionalities. Errors fr
317320

318321
## Authors
319322

320-
- Przemysław Lenart, przemek.lenart@polidea.com~
323+
- Przemysław Lenart, przemek.lenart@polidea.com
321324
- Kacper Harasim, kacper.harasim@polidea.com
322325

323326

324-
325327
## Contributing
326328
If you would like to contribute code you can do so through GitHub by forking the repository and sending a pull request.
327329
To keep code in order, we advice you to use SwiftLint. In repository, we provide configured `.swiftlint.yml` file, that matches our criteria of clean and "Swifty" code.
@@ -330,8 +332,19 @@ To keep code in order, we advice you to use SwiftLint. In repository, we provide
330332

331333
Maciek Oczko (maciek.oczko@polidea.com)
332334

333-
[moogle19](https://github.com/moogle19)
334-
[abeintopalo](https://github.com/abeintopalo)
335+
Paweł Janeczek (pawel.janeczek@polidea.com)
336+
337+
Michał Laskowski (michal.laskowski@polidea.com)
338+
339+
Kamil Kosowski (kamil.kosowski@polidea.com)
340+
341+
Paweł Ścibek (pawel.scibek@polidea.com)
342+
343+
Bartosz Stelmaszuk (bartosz.stelmaszuk@polidea.com)
344+
345+
Krzysztof Siejkowski (krzysztof.siejkowski@polidea.com)
346+
347+
[moogle19](https://github.com/moogle19), [abeintopalo](https://github.com/abeintopalo), [DevAndArtist](https://github.com/DevAndArtist), [HAKASHUN](https://github.com/HAKASHUN), [fnazarios](https://github.com/fnazarios), [robnadin](https://github.com/robnadin), [Orgmir](https://github.com/Orgmir), [cwalcott](https://github.com/cwalcott), [KrauseFx](https://github.com/KrauseFx)
335348

336349
## License
337350

0 commit comments

Comments
 (0)