Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/eugene-software/cbcbluetooth
Convenient Combine wrapper for CoreBluetooth
https://github.com/eugene-software/cbcbluetooth
ble bluetooth combine corebluetooth ios macos reactive swift watchos
Last synced: about 2 months ago
JSON representation
Convenient Combine wrapper for CoreBluetooth
- Host: GitHub
- URL: https://github.com/eugene-software/cbcbluetooth
- Owner: eugene-software
- License: mit
- Created: 2022-10-19T17:44:33.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-10-08T11:32:40.000Z (3 months ago)
- Last Synced: 2024-11-02T14:51:33.975Z (2 months ago)
- Topics: ble, bluetooth, combine, corebluetooth, ios, macos, reactive, swift, watchos
- Language: Swift
- Homepage:
- Size: 74.2 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CBCBluetooth
[![Version](https://img.shields.io/cocoapods/v/CBCBluetooth.svg?style=flat-square)](https://cocoapods.org/pods/CBCBluetooth)
[![License](https://img.shields.io/cocoapods/l/CBCBluetooth.svg?style=flat-square)](https://cocoapods.org/pods/CBCBluetooth)
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Feugene-software%2FCBCBluetooth%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/eugene-software/CBCBluetooth)
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Feugene-software%2FCBCBluetooth%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/eugene-software/CBCBluetooth)## Requirements
- iOS 13 and above
## Usage Example
Import dependenices:
```swift
import Combine
import CoreBluetooth
import CBCBluetooth
```- Scanning and receiving single value from public services:
```swift
let manager = CBCCentralManagerFactory.create()
let service = "SOME-SERVICE-UUID-STRING"
let characteristic = "SOME-CHARACTERISTIC-UUID-STRING"manager.startScan(with: [service])
.flatMap {
$0.discoverServices(with: [service])
}
.flatMap {
$0.discoverCharacteristics(with: [characteristic])
}
.flatMap {
$0.readValue()
}
.sink { completion in
print(completion)
} receiveValue: { response in
print(response.data)
}
.store(in: &cancellables)
```- Connecting to particular peripheral by UUID:
```swift
let manager = CBCCentralManagerFactory.create()
let peripheralUUID = UUID(uuidString: "SOME-PERIPHERAL-UUID-STRING")!manager.getPeripherals(with: [peripheralUUID])
.first()
.flatMap {
$0.connect()
}
.sink { completion in
print(completion)
} receiveValue: { peripheral in
print(peripheral)
}
.store(in: &cancellables)
```- Observe RSSI:
```swift
let manager = CBCCentralManagerFactory.create()
let peripheralUUID = UUID(uuidString: "SOME-PERIPHERAL-UUID-STRING")!manager.getPeripherals(with: [peripheralUUID])
.first()
.flatMap {
$0.connect()
}
.flatMap {
$0.observeRSSI()
}
.sink { completion in
print(completion)
} receiveValue: { rssi in
print(rssi)
}
.store(in: &cancellables)
```## Installation
### Cocoapods
CBCBluetooth is available through [CocoaPods](https://cocoapods.org). To install
it, simply add the following line to your Podfile:```ruby
pod 'CBCBluetooth'
```### Swift Package Manager
1. Right click in the Project Navigator
2. Select "Add Packages..."
3. Search for ```https://github.com/eugene-software/CBCBluetooth.git```## Author
Eugene Software
## License
CBCBluetooth is available under the MIT license. See the LICENSE file for more info.