CBCBluetooth

Version License

要求

使用示例

导入依赖

import Combine
import CoreBluetooth
import CBCBluetooth
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)
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)
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)

安装

Cocoapods

CBCBluetooth 可通过 CocoaPods 获得。 要安装它,只需将以下行添加到你的 Podfile 中

pod 'CBCBluetooth'

Swift Package Manager

  1. 在项目导航器中右键单击
  2. 选择 “添加包…”
  3. 搜索 https://github.com/eugene-software/CBCBluetooth.git

作者

Eugene Software

许可

CBCBluetooth 使用 MIT 许可证。 详情请参阅 LICENSE 文件。