From 0505e435a619ffe600cc2e652b0965c49bf607d7 Mon Sep 17 00:00:00 2001 From: Diogo Cruz Diniz Date: Sat, 13 Jun 2026 21:35:09 +0100 Subject: [PATCH] feat: BLE beacond --- Sources/scoobytag/BluetoothManager.swift | 29 ++++++++++++++++-------- 1 file changed, 19 insertions(+), 10 deletions(-) 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" + } } } -}