feat: Simple bluetooth status indication
This commit is contained in:
23
Sources/scoobytag/BluetoothManager.swift
Normal file
23
Sources/scoobytag/BluetoothManager.swift
Normal 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"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user