24 lines
579 B
Swift
24 lines
579 B
Swift
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"
|
|
}
|
|
}
|
|
}
|