mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
Bump minimum version to 2.0.0
Revert BLE Connect updates
This commit is contained in:
parent
cf276bbf99
commit
9ec67ed7d7
2 changed files with 43 additions and 66 deletions
|
|
@ -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!")
|
||||
// }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue