Files
Companion/Sources/scoobytag/BluetoothManager.swift
2026-06-13 21:35:09 +01:00

33 lines
969 B
Swift

import SwiftUI
import CoreBluetooth
final class BluetoothManager: NSObject, ObservableObject {
private var periphManager: CBPeripheralManager!
@Published var status = "Starting..."
override init() {
super.init()
periphManager = CBPeripheralManager(delegate: self, queue: nil)
}
}
extension BluetoothManager: CBPeripheralManagerDelegate {
func peripheralManagerDidUpdateState(_ central: CBPeripheralManager) {
switch central.state {
case .poweredOn:
status = "Broadcasting"
let uuid = CBUUID(string: "12345678-1234-1234-1234-123456789ABC")
periphManager.startAdvertising(
[
CBAdvertisementDataServiceUUIDsKey: [uuid],
CBAdvertisementDataLocalNameKey: "scbt-Test"
])
case .poweredOff:
status = "Bluetooth off"
default:
status = "Bluetooth unavailable"
}
}
}