All Projects → StarryInternet → CombineCoreBluetooth

StarryInternet / CombineCoreBluetooth

Licence: MIT License
A wrapper API for CoreBluetooth using Combine Publishers

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to CombineCoreBluetooth

Opencombine
Open source implementation of Apple's Combine framework for processing values over time.
Stars: ✭ 2,040 (+3980%)
Mutual labels:  tvos, watchos, reactive-programming, combine
Conbini
Publishers, operators, and subscribers to supplement Combine.
Stars: ✭ 109 (+118%)
Mutual labels:  tvos, watchos, reactive-programming
Open Source Ios Apps
📱 Collaborative List of Open-Source iOS Apps
Stars: ✭ 28,826 (+57552%)
Mutual labels:  tvos, watchos, reactive-programming
Extendable
Blocks Based Bluetooth LE Connectivity framework for iOS/watchOS/tvOS/OSX. Quickly configure centrals & peripherals, perform read/write operations, and respond characteristic updates.
Stars: ✭ 88 (+76%)
Mutual labels:  tvos, watchos, bluetooth
Berkanansdk
Bluetooth mesh messaging SDK for apps
Stars: ✭ 150 (+200%)
Mutual labels:  tvos, watchos, bluetooth
lisk-swift
Swift 4 library for Lisk - Including Local Signing for maximum security
Stars: ✭ 13 (-74%)
Mutual labels:  tvos, watchos
stinsen
Coordinators in SwiftUI. Simple, powerful and elegant.
Stars: ✭ 563 (+1026%)
Mutual labels:  tvos, watchos
swiftui-mapkit
SwiftUI meets MapKit
Stars: ✭ 17 (-66%)
Mutual labels:  reactive-programming, combine
SwiftObserver
Elegant Reactive Primitives for Clean Swift Architecture #NoRx
Stars: ✭ 14 (-72%)
Mutual labels:  reactive-programming, combine
QuoteKit
A framework to use the free APIs provided by https://quotable.io
Stars: ✭ 17 (-66%)
Mutual labels:  tvos, watchos
CoordinatorSwiftUI
A simple project to test the implementation of Coordinator Pattern using SwiftUI.
Stars: ✭ 28 (-44%)
Mutual labels:  watchos, combine
Johnny
Melodic Caching for Swift
Stars: ✭ 36 (-28%)
Mutual labels:  tvos, watchos
Dots
Lightweight Concurrent Networking Framework
Stars: ✭ 35 (-30%)
Mutual labels:  tvos, watchos
IrregularGradient
Create animated irregular gradients in SwiftUI.
Stars: ✭ 127 (+154%)
Mutual labels:  tvos, watchos
SeedTruck
Torrent management app for iOS, macOS, tvOS and watchOS made in SwiftUI 2. Same codebase for all platforms!
Stars: ✭ 25 (-50%)
Mutual labels:  tvos, watchos
tracelog
TraceLog is a highly configurable, flexible, portable, and simple to use debug logging system for Swift and Objective-C applications running on Linux, macOS, iOS, watchOS, and tvOS.
Stars: ✭ 52 (+4%)
Mutual labels:  tvos, watchos
SwiftRadix
Easily convert integers to binary/hex/octal strings and back again with clean functional syntax.
Stars: ✭ 34 (-32%)
Mutual labels:  tvos, watchos
GATT
Bluetooth Generic Attribute Profile (GATT) for Swift (Supports Linux)
Stars: ✭ 48 (-4%)
Mutual labels:  bluetooth, corebluetooth
Mechanica
A cross-platform library of Swift utils to ease your iOS | macOS | watchOS | tvOS and Linux development.
Stars: ✭ 27 (-46%)
Mutual labels:  tvos, watchos
Columbus
A feature-rich country picker for iOS, tvOS and watchOS.
Stars: ✭ 23 (-54%)
Mutual labels:  tvos, watchos

CombineCoreBluetooth

CI GitHub

CombineCoreBluetooth is a library that bridges Apple's CoreBluetooth framework and Apple's Combine framework, making it possible to subscribe to perform bluetooth operations while subscribing to a publisher of the results of those operations, instead of relying on implementing delegates and manually filtering for the results you need.

Requirements:

  • iOS 13, tvOS 13, macOS 10.15, or watchOS 6
  • Xcode 12 or higher
  • Swift 5.3 or higher

Installation

Swift Package Manager

Add this line to your dependencies list in your Package.swift:

.package(name: "CombineCoreBluetooth", url: "https://github.com/StarryInternet/CombineCoreBluetooth.git", from: "0.3.0"),

Cocoapods

Add this line to your Podfile:

pod 'CombineCoreBluetooth'

Carthage

Add this line to your Cartfile:

github "StarryInternet/CombineCoreBluetooth"

Usage

This library is heavily inspired by pointfree.co's approach 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.

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 Peripherals returned by discovering and connected to via the CentralManager type.

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:

let serviceID = CBUUID(string: "0123")

centralManager.scanForPeripherals(withServices: [serviceID])
  .first()
  .assign(to: \.peripheralDiscovery, on: self) // property of type PeripheralDiscovery
  .store(in: &cancellables)

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:

// use whatever ids your peripheral advertises here
let characteristicID = CBUUID(string: "4567")

peripheralDiscovery.peripheral
  .readValue(forCharacteristic: characteristicID, inService: serviceID)
  .sink(receiveCompletion: { completion in
    // handle any potential errors here
  }, receiveValue: { data in
   // handle data from characteristic here, or add more publisher methods to map and transform it.
  })
  .store(in: &cancellables)

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.

Caveats

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.

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].