Swiftpack.co - eugene-software/CBCBluetooth as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by eugene-software.
eugene-software/CBCBluetooth 1.0.4
Convenient Combine wrapper for CoreBluetooth
⭐️ 3
🕓 2 weeks ago
iOS
.package(url: "https://github.com/eugene-software/CBCBluetooth.git", from: "1.0.4")

CBCBluetooth

Version License Platform

Requirements

  • iOS 13 and above

Usage Example

Import dependenices:

import Combine
import CoreBluetooth
import CBCBluetooth
  • Scanning and receiving single value from public services:

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:
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:
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. To install it, simply add the following line to your Podfile:

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.

GitHub

link
Stars: 3
Last commit: 2 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

1.0.4
2 weeks ago

Rollback to use Strings for Services

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics