Add path to notifications

This commit is contained in:
Garth Vander Houwen 2024-01-20 14:05:29 -08:00
parent a9e90e5b85
commit f2056aa1ac
6 changed files with 77 additions and 47 deletions

View file

@ -215,7 +215,9 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate
id: (peripheral.identifier.uuidString),
title: "Radio Disconnected",
subtitle: "\(peripheral.name ?? "unknown".localized)",
content: e.localizedDescription
content: e.localizedDescription,
target: "bluetooth",
path: "meshtastic://bluetooth"
)
]
manager.schedule()
@ -233,7 +235,9 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate
id: (peripheral.identifier.uuidString),
title: "Radio Disconnected",
subtitle: "\(peripheral.name ?? "unknown".localized)",
content: e.localizedDescription
content: e.localizedDescription,
target: "bluetooth",
path: "meshtastic://bluetooth"
)
]
manager.schedule()

View file

@ -31,15 +31,19 @@ class LocalNotificationManager {
// This function iterates over the Notification objects in the notifications array and schedules them for delivery in the future
private func scheduleNotifications() {
for notification in notifications {
let content = UNMutableNotificationContent()
content.subtitle = notification.subtitle
content.title = notification.title
content.body = notification.content
content.sound = .default
content.interruptionLevel = .timeSensitive
let content = UNMutableNotificationContent()
content.subtitle = notification.subtitle
content.title = notification.title
content.body = notification.content
content.sound = .default
content.interruptionLevel = .timeSensitive
if notification.target != nil {
content.userInfo["target"] = notification.target
}
if notification.path != nil {
content.userInfo["path"] = notification.path
}
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1, repeats: false)
let request = UNNotificationRequest(identifier: notification.id, content: content, trigger: trigger)
@ -69,4 +73,5 @@ struct Notification {
var subtitle: String
var content: String
var target: String?
var path: String?
}

View file

@ -660,23 +660,37 @@ func telemetryPacket(packet: MeshPacket, connectedNode: Int64, context: NSManage
// Connected Device Metrics
// ------------------------
// Low Battery notification
if telemetry.batteryLevel > 0 && telemetry.batteryLevel < 5 {
let content = UNMutableNotificationContent()
content.title = "Critically Low Battery!"
content.body = "Time to charge your radio, there is \(telemetry.batteryLevel)% battery remaining."
content.userInfo["target"] = "node"
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1, repeats: false)
let uuidString = UUID().uuidString
let request = UNNotificationRequest(identifier: uuidString, content: content, trigger: trigger)
let notificationCenter = UNUserNotificationCenter.current()
notificationCenter.add(request) { (error) in
if error != nil {
// Handle any errors.
print("Error creating local low battery notification: \(error?.localizedDescription ?? "no description")")
} else {
print("Created local low battery notification.")
}
}
if telemetry.batteryLevel > 0 && telemetry.batteryLevel < 4 {
let manager = LocalNotificationManager()
manager.notifications = [
Notification(
id: ("notification.id.\(UUID().uuidString)"),
title: "Critically Low Battery!",
subtitle: "AKA \(telemetry.nodeTelemetry?.user?.shortName ?? "UNK")",
content: "Time to charge your radio, there is \(telemetry.batteryLevel)% battery remaining.",
target: "nodes",
path: "meshtastic://nodes/\(telemetry.nodeTelemetry?.num ?? 0)/devicetelemetrylog"
)
]
manager.schedule()
// let content = UNMutableNotificationContent()
// content.title = "Critically Low Battery!"
// content.body = "Time to charge your radio, there is \(telemetry.batteryLevel)% battery remaining."
// content.userInfo["target"] = "node"
// content.userInfo["path"] = "meshtastic://node/\(telemetry.nodeTelemetry?.num ?? 0)"
// let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1, repeats: false)
// let uuidString = UUID().uuidString
// let request = UNNotificationRequest(identifier: uuidString, content: content, trigger: trigger)
// let notificationCenter = UNUserNotificationCenter.current()
// notificationCenter.add(request) { (error) in
// if error != nil {
// // Handle any errors.
// print("Error creating local low battery notification: \(error?.localizedDescription ?? "no description")")
// } else {
// print("Created local low battery notification.")
// }
// }
}
// Update our live activity if there is one running, not available on mac iOS >= 16.2
#if !targetEnvironment(macCatalyst)
@ -781,7 +795,8 @@ func textMessageAppPacket(packet: MeshPacket, blockRangeTest: Bool, connectedNod
title: "\(newMessage.fromUser?.longName ?? "unknown".localized)",
subtitle: "AKA \(newMessage.fromUser?.shortName ?? "?")",
content: messageText,
target: "message"
target: "message",
path: "meshtastic://messages/dm/user/\(newMessage.fromUser?.num ?? 0)/message/\(newMessage.messageId)"
)
]
manager.schedule()
@ -812,7 +827,8 @@ func textMessageAppPacket(packet: MeshPacket, blockRangeTest: Bool, connectedNod
title: "\(newMessage.fromUser?.longName ?? "unknown".localized)",
subtitle: "AKA \(newMessage.fromUser?.shortName ?? "?")",
content: messageText,
target: "message")
target: "message",
path: "meshtastic://messages/channel/\(newMessage.messageId)")
]
manager.schedule()
print("💬 iOS Notification Scheduled for text message from \(newMessage.fromUser?.longName ?? "unknown".localized)")
@ -878,7 +894,8 @@ func waypointPacket (packet: MeshPacket, context: NSManagedObjectContext) {
title: "New Waypoint Received",
subtitle: "\(icon) \(waypoint.name ?? "Dropped Pin")",
content: "\(waypoint.longDescription ?? "\(latitude), \(longitude)")",
target: "map"
target: "map",
path: "meshtastic://map/waypoint/\(waypoint.id)"
)
]
manager.schedule()

View file

@ -31,6 +31,21 @@
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>CFBundleURLIconFile</key>
<string>alpha</string>
<key>CFBundleURLName</key>
<string>org.meshtastic</string>
<key>CFBundleURLSchemes</key>
<array>
<string>meshtastic</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>INIntentsSupported</key>
@ -52,17 +67,17 @@
<key>NSBluetoothAlwaysUsageDescription</key>
<string>We use bluetooth to connect to nearby Meshtastic Devices</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>Bluetooth is used to connect an iPhone to a user&apos;s meshtastic device to allow text messaging and location data for the mesh network.</string>
<string>Bluetooth is used to connect an iPhone to a user's meshtastic device to allow text messaging and location data for the mesh network.</string>
<key>NSCameraUsageDescription</key>
<string>We use the camera to share channels using a QR Code</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>We use your location to display it on the mesh map as well as to have GPS coordinatess to send to the connected device. Route Recording uses location in the background.</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>We use your location to display it on the mesh map as well as to have GPS coordinatess to send to the connected device.</string>
<key>NSLocationUsageDescription</key>
<string>We use your location to display it on the mesh map as well as to have GPS coordinatess to send to the connected device.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>We use your location to display it on the mesh map as well as to have GPS coordinatess to send to the connected device.</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>We use your location to display it on the mesh map as well as to have GPS coordinatess to send to the connected device.</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>We use your location to display it on the mesh map as well as to have GPS coordinatess to send to the connected device. Route Recording uses location in the background.</string>
<key>NSSupportsLiveActivities</key>
<true/>
<key>Privacy Bluetooth Always Usage Description</key>
@ -71,20 +86,6 @@
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<true/>
<key>UISceneConfigurations</key>
<dict>
<key>CPTemplateApplicationSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneClassName</key>
<string>CPTemplateApplicationScene</string>
<key>UISceneDelegateClassName</key>
<string>$(SWIFT_MODULE_NAME).CarPlaySceneDelegate</string>
<key>UISceneConfigurationName</key>
<string>CarPlay scene</string>
</dict>
</array>
</dict>
</dict>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>

View file

@ -153,4 +153,5 @@ class AppState: ObservableObject {
@Published var unreadChannelMessages: Int = 0
@Published var firmwareVersion: String = "0.0.0"
@Published var connectedNode: NodeInfoEntity?
@Published var navigationPath: String?
}

View file

@ -33,6 +33,8 @@ class MeshtasticAppDelegate: NSObject, UIApplicationDelegate, UNUserNotification
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
let targetValue = userInfo["target"] as? String
AppState.shared.navigationPath = userInfo["path"] as? String
print("\(AppState.shared.navigationPath ?? "EMPTY")")
if targetValue == "map" {
AppState.shared.tabSelection = Tab.map
} else if targetValue == "message" {