diff --git a/Sources/scoobytag/BluetoothManager.swift b/Sources/scoobytag/BluetoothManager.swift index 1694d91..d8dcdbe 100644 --- a/Sources/scoobytag/BluetoothManager.swift +++ b/Sources/scoobytag/BluetoothManager.swift @@ -2,22 +2,31 @@ import SwiftUI import CoreBluetooth final class BluetoothManager: NSObject, ObservableObject { - private var centralManager: CBCentralManager! + private var periphManager: CBPeripheralManager! @Published var status = "Starting..." override init() { super.init() - centralManager = CBCentralManager(delegate: self, queue: nil) + periphManager = CBPeripheralManager(delegate: self, queue: nil) } } -extension BluetoothManager: CBCentralManagerDelegate { - func centralManagerDidUpdateState(_ central: CBCentralManager) { - switch central.state { - case .poweredOn: - status = "Bluetooth is on" - default: - status = "Bluetooth unavailable" +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" + } } } -}