diff --git a/Meshtastic/Helpers/BLEManager.swift b/Meshtastic/Helpers/BLEManager.swift index 5bad8ad4..7964d860 100644 --- a/Meshtastic/Helpers/BLEManager.swift +++ b/Meshtastic/Helpers/BLEManager.swift @@ -30,7 +30,7 @@ class BLEManager: NSObject, CBPeripheralDelegate, ObservableObject { @Published var isSwitchedOn: Bool = false @Published var automaticallyReconnect: Bool = true - public var minimumVersion = "1.3.48" + public var minimumVersion = "2.0.0" public var connectedVersion: String public var isConnecting: Bool = false public var isConnected: Bool = false @@ -62,8 +62,8 @@ class BLEManager: NSObject, CBPeripheralDelegate, ObservableObject { self.lastConnectionError = "" self.connectedVersion = "0.0.0" super.init() - //centralManager = CBCentralManager(delegate: self, queue: nil) - centralManager = CBCentralManager(delegate: self, queue: nil, options: [CBCentralManagerOptionRestoreIdentifierKey: restoreKey]) + centralManager = CBCentralManager(delegate: self, queue: nil) + //centralManager = CBCentralManager(delegate: self, queue: nil, options: [CBCentralManagerOptionRestoreIdentifierKey: restoreKey]) } // MARK: Scanning for BLE Devices @@ -2011,28 +2011,28 @@ extension BLEManager: CBCentralManagerDelegate { self.peripherals.removeAll(where: { $0.lastUpdate < visibleDuration}) } - func centralManager(_ central: CBCentralManager, willRestoreState dict: [String : Any]) { - - guard let peripherals = dict[CBCentralManagerRestoredStatePeripheralsKey] as? [CBPeripheral] else { - return - } - - if peripherals.count > 0 { - - for peripheral in peripherals { - print(peripheral) - switch peripheral.state { - case .connecting: // I've only seen this happen when - // re-launching attached to Xcode. - print("Xcode Restore") - - case .connected: - connectTo(peripheral: peripheral) - print("Restore BLE State") - default: break - } - } - } - print("willRestoreState Hit!") - } +// func centralManager(_ central: CBCentralManager, willRestoreState dict: [String : Any]) { +// +// guard let peripherals = dict[CBCentralManagerRestoredStatePeripheralsKey] as? [CBPeripheral] else { +// return +// } +// +// if peripherals.count > 0 { +// +// for peripheral in peripherals { +// print(peripheral) +// switch peripheral.state { +// case .connecting: // I've only seen this happen when +// // re-launching attached to Xcode. +// print("Xcode Restore") +// +// case .connected: +// connectTo(peripheral: peripheral) +// print("Restore BLE State") +// default: break +// } +// } +// } +// print("willRestoreState Hit!") +// } } diff --git a/Meshtastic/Views/Bluetooth/Connect.swift b/Meshtastic/Views/Bluetooth/Connect.swift index 5b7cc29c..0f7affb4 100644 --- a/Meshtastic/Views/Bluetooth/Connect.swift +++ b/Meshtastic/Views/Bluetooth/Connect.swift @@ -21,8 +21,6 @@ struct Connect: View { @State var isPreferredRadio: Bool = false @State var isUnsetRegion = false @State var invalidFirmwareVersion = false - @State var isPresentingPreferredPeripherialDialog = false - @State var showDialogForNextPeripherialChange = true var body: some View { @@ -63,44 +61,23 @@ struct Connect: View { Toggle("preferred.radio", isOn: $bleManager.preferredPeripheral) .toggleStyle(SwitchToggleStyle(tint: .accentColor)) .labelsHidden() - .confirmationDialog( - "Are you sure? Switching your preferred peripheral will clear all app data from the phone.", - isPresented: $isPresentingPreferredPeripherialDialog, - titleVisibility: .visible - ) { - Button("Confirm", role: .destructive) { - - if bleManager.preferredPeripheral { - if bleManager.connectedPeripheral != nil { - userSettings.preferredPeripheralId = bleManager.connectedPeripheral!.peripheral.identifier.uuidString - userSettings.preferredNodeNum = bleManager.connectedPeripheral!.num - bleManager.preferredPeripheral = true - isPreferredRadio = true - showDialogForNextPeripherialChange = false - } - } else { - - if bleManager.connectedPeripheral != nil && bleManager.connectedPeripheral.peripheral.identifier.uuidString == userSettings.preferredPeripheralId { - userSettings.preferredPeripheralId = "" - userSettings.preferredNodeNum = 0 - bleManager.preferredPeripheral = false - isPreferredRadio = false - } - } - bleManager.disconnectPeripheral() - clearCoreDataDatabase(context: context) - } - Button("Cancel", role: .cancel) { - showDialogForNextPeripherialChange = false - bleManager.preferredPeripheral = !bleManager.preferredPeripheral - } - } .onChange(of: bleManager.preferredPeripheral) { value in - - if showDialogForNextPeripherialChange { - isPresentingPreferredPeripherialDialog = true - } else { - showDialogForNextPeripherialChange = true + if value { + if bleManager.connectedPeripheral != nil { + userSettings.preferredPeripheralId = bleManager.connectedPeripheral!.peripheral.identifier.uuidString + userSettings.preferredNodeNum = bleManager.connectedPeripheral!.num + bleManager.preferredPeripheral = true + isPreferredRadio = true + } + } else { + + if bleManager.connectedPeripheral != nil && bleManager.connectedPeripheral.peripheral.identifier.uuidString == userSettings.preferredPeripheralId { + + userSettings.preferredPeripheralId = "" + userSettings.preferredNodeNum = 0 + bleManager.preferredPeripheral = false + isPreferredRadio = false + } } } }