feat: Simple bluetooth status indication

This commit is contained in:
2026-06-07 18:27:33 +01:00
commit 61bf63fd14
9 changed files with 125 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
import SwiftUI
import CoreBluetooth
final class BluetoothManager: NSObject, ObservableObject {
private var centralManager: CBCentralManager!
@Published var status = "Starting..."
override init() {
super.init()
centralManager = CBCentralManager(delegate: self, queue: nil)
}
}
extension BluetoothManager: CBCentralManagerDelegate {
func centralManagerDidUpdateState(_ central: CBCentralManager) {
switch central.state {
case .poweredOn:
status = "Bluetooth is on"
default:
status = "Bluetooth unavailable"
}
}
}

View File

@@ -0,0 +1,16 @@
import SwiftUI
struct ContentView: View {
@EnvironmentObject var bluetoothManager: BluetoothManager
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Hello, world!")
Text(bluetoothManager.status)
}
.padding()
}
}

View File

@@ -0,0 +1,13 @@
import SwiftUI
import CoreBluetooth
@main
struct ScoobyTagApp: App {
@StateObject private var bluetoothManager = BluetoothManager()
var body: some Scene {
WindowGroup {
ContentView()
.environmentObject(bluetoothManager)
}
}
}