Skip to content

Commit 9027149

Browse files
committed
readme update
1 parent 7315341 commit 9027149

File tree

1 file changed

+50
-8
lines changed

1 file changed

+50
-8
lines changed

README.md

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,60 @@ CombineCoreBluetooth is a library that bridges Apple's `CoreBluetooth` framework
99

1010
## Requirements:
1111

12-
* iOS 13, tvOS 13, macOS 10.15, or watchOS 6
13-
* Xcode 12 or higher
14-
* Swift 5.3 or higher
12+
- iOS 13, tvOS 13, macOS 10.15, or watchOS 6
13+
- Xcode 12 or higher
14+
- Swift 5.3 or higher
15+
16+
## Installation
17+
18+
### Swift Package Manager
19+
20+
Add this line to your dependencies list in your Package.swift:
21+
22+
```swift
23+
.package(name: "CombineCoreBluetooth", url: "https://github.com/StarryInternet/CombineCoreBluetooth.git", from: "0.2.0"),
24+
```
25+
26+
### Cocoapods
27+
28+
Add this line to your Podfile:
29+
30+
```ruby
31+
pod 'CombineCoreBluetooth'
32+
```
33+
34+
### Carthage
35+
36+
Add this line to your Cartfile:
37+
38+
```
39+
github "StarryInternet/CombineCoreBluetooth"
40+
```
1541

1642
## Usage
1743

18-
This library is heavily inspired by [pointfree.co's approach](https://www.pointfree.co/collections/dependencies) to designing dependencies, but with some customizations. Many asynchronous operations returns their own `Publisher` or expose their own long-lived publisher you can subscribe to. To do something like fetching a value from a characteristic, for instance, you could call the following methods on the `Peripheral` type and subscribe to the resulting `Publisher`:
44+
This library is heavily inspired by [pointfree.co's approach](https://www.pointfree.co/collections/dependencies) to designing dependencies, but with some customizations. Many asynchronous operations returns their own `Publisher` or expose their own long-lived publisher you can subscribe to.
45+
46+
This library doesn't maintain any additional state beyond what's needed to enable this library to provide a combine-centric API. This means that you are responsible for maintaining any state necessary, including holding onto any `Peripheral`s returned by discovering and connected to via the `CentralManager` type.
47+
48+
To scan for a peripheral, much like in plain CoreBluetooth, you call the `scanForPeripherals(withServices:options:)` method. However, on this library's `CentralManager` type, this returns a publisher of `PeripheralDiscovery` values. If you want to store a peripheral for later use, you could subscribe to the returned publisher by doing something like this:
1949

2050
```swift
21-
// use whatever ids your peripheral advertises here
2251
let serviceID = CBUUID(string: "0123")
52+
53+
centralManager.scanForPeripherals(withServices: [serviceID])
54+
.first()
55+
.assign(to: \.peripheralDiscovery, on: self) // property of type PeripheralDiscovery
56+
.store(in: &cancellables)
57+
```
58+
59+
To do something like fetching a value from a characteristic, for instance, you could call the following methods on the `Peripheral` type and subscribe to the resulting `Publisher`:
60+
61+
```swift
62+
// use whatever ids your peripheral advertises here
2363
let characteristicID = CBUUID(string: "4567")
2464

25-
peripheral
65+
peripheralDiscovery.peripheral
2666
.readValue(forCharacteristic: characteristicID, inService: serviceID)
2767
.sink(receiveCompletion: { completion in
2868
// handle any potential errors here
@@ -32,8 +72,10 @@ peripheral
3272
.store(in: &cancellables)
3373
```
3474

35-
The `Peripheral` type (created and given to you by the `CentralManager` type) here will filter the results from the given delegate methods, and only send values that match the service and characteristic IDs down to subscribers or child publishers.
75+
The publisher returned in `readValue` will only send values that match the service and characteristic IDs through to any subscribers, so you don't need to worry about any filtering logic yourself. Note that if the `Peripheral` never receives a value from this characteristic over bluetooth, it will never send a value into the publisher, so you may want to add a timeout if your use case requires it.
3676

3777
## Caveats
3878

39-
All major types from `CoreBluetooth` should be available in this library, wrapped in their own types to provide the `Combine`-centric API. This library has been tested in production for most `CentralManager` related operations. Apps acting as bluetooth peripherals are also supported using the `PeripheralManager` type, but that side hasn't been as rigorously tested.
79+
All major types from `CoreBluetooth` should be available in this library, wrapped in their own types to provide the `Combine`-centric API. This library has been tested in production for most `CentralManager` related operations. Apps acting as bluetooth peripherals are also supported using the `PeripheralManager` type, but that side hasn't been as rigorously tested.
80+
81+
As of version 0.2, all write characteristic operations expect a response even if those characteristics are not specified by the peripheral to respond on write completion; this means that the publisher will never complete if you attempt to write to characteristics that don't respond. Until this is changed, you are responsible for managing the lifetime of publishers for writeable characteristics with these properties

0 commit comments

Comments
 (0)