Skip to content

NoahKnudsen/AsyncBluetooth

Repository files navigation

AsyncBluetooth

Core Bluetooth + Structured Concurrency

Basic Usages (more to come):

Using a for await-in loop to inspect each bluetooth peripheral discovered:

let bluetooth = Bluetooth()

for try await discovered in bluetooth.discoverPeripherals() {
  guard discovered.peripheral.name == "Target Name" else { continue }

  bluetooth.stopDiscovering()

  try await discovered.peripheral.connect()
  ...
}

Using an AsyncSequence single value method to eliminate for loops

let bluetooth = Bluetooth()
        
let discovered = try await bluetooth
  .discoverPeripherals(withServiceIds: [CBUUID(string: "AAA")])
  .first{ $0.advertisementData["kCBAdvDataManufacturerData"] ... }

guard let peripheral = discovered?.peripheral else { return }
        
try await peripheral.connect()

About

Core Bluetooth + Structured Concurrency

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages