mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
Added notifications for a preferred devic disconnecting
This commit is contained in:
parent
13e752cd4e
commit
e7cde6596c
1 changed files with 25 additions and 0 deletions
|
|
@ -199,6 +199,7 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate
|
|||
self.isConnecting = false
|
||||
self.isConnected = false
|
||||
self.isSubscribed = false
|
||||
let manager = LocalNotificationManager()
|
||||
if let e = error {
|
||||
// https://developer.apple.com/documentation/corebluetooth/cberror/code
|
||||
let errorCode = (e as NSError).code
|
||||
|
|
@ -208,6 +209,18 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate
|
|||
print("🚨 BLE Disconnected: \(peripheral.name ?? "Unknown") Error Code: \(errorCode) Error: \(e.localizedDescription)")
|
||||
} else if errorCode == 7 { // CBError.Code.peripheralDisconnected The specified device has disconnected from us.
|
||||
// Seems to be what is received when a tbeam sleeps, immediately recconnecting does not work.
|
||||
if UserDefaults.preferredPeripheralId == peripheral.identifier.uuidString{
|
||||
manager.notifications = [
|
||||
Notification(
|
||||
id: (peripheral.identifier.uuidString),
|
||||
title: "Disconnected from Preferred Device",
|
||||
subtitle: "Device: \(peripheral.name ?? "unknown".localized)",
|
||||
content: "Error Code: 7, seems to be what is received when a tbeam sleeps, immediately recconnecting does not work.",
|
||||
target: "device"
|
||||
)
|
||||
]
|
||||
manager.schedule()
|
||||
}
|
||||
lastConnectionError = "🚨 \(e.localizedDescription)"
|
||||
print("🚨 BLE Disconnected: \(peripheral.name ?? "Unknown") Error Code: \(errorCode) Error: \(e.localizedDescription)")
|
||||
} else if errorCode == 14 { // Peer removed pairing information
|
||||
|
|
@ -215,6 +228,18 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate
|
|||
lastConnectionError = "🚨 " + String.localizedStringWithFormat("ble.errorcode.14 %@".localized, e.localizedDescription)
|
||||
print("🚨 BLE Disconnected: \(peripheral.name ?? "Unknown") Error Code: \(errorCode) Error: \(lastConnectionError)")
|
||||
} else {
|
||||
if UserDefaults.preferredPeripheralId == peripheral.identifier.uuidString{
|
||||
manager.notifications = [
|
||||
Notification(
|
||||
id: (peripheral.identifier.uuidString),
|
||||
title: "Disconnected from Preferred Device",
|
||||
subtitle: "Device: \(peripheral.name ?? "unknown".localized)",
|
||||
content: "Error Code: \(errorCode), \(e.localizedDescription)",
|
||||
target: "device"
|
||||
)
|
||||
]
|
||||
manager.schedule()
|
||||
}
|
||||
lastConnectionError = "🚨 \(e.localizedDescription)"
|
||||
print("🚨 BLE Disconnected: \(peripheral.name ?? "Unknown") Error Code: \(errorCode) Error: \(e.localizedDescription)")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue