ios push notifications

This commit is contained in:
Trey t
2025-11-13 16:13:36 -06:00
parent b2f2627ad5
commit ff390a85c2
5 changed files with 37 additions and 30 deletions

View File

@@ -63,7 +63,7 @@ class PushNotificationManager: NSObject, ObservableObject {
print("⚠️ No auth token available, will register device after login")
return
}
let request = DeviceRegistrationRequest(
registrationId: token,
platform: "ios"
@@ -93,10 +93,10 @@ class PushNotificationManager: NSObject, ObservableObject {
if let notificationId = userInfo["notification_id"] as? String {
print("Notification ID: \(notificationId)")
// // Mark as read when user taps notification
// Task {
// await markNotificationAsRead(notificationId: notificationId)
// }
// Mark as read when user taps notification
Task {
await markNotificationAsRead(notificationId: notificationId)
}
}
if let type = userInfo["type"] as? String {
@@ -130,24 +130,24 @@ class PushNotificationManager: NSObject, ObservableObject {
}
}
// private func markNotificationAsRead(notificationId: String) async {
// guard TokenStorage.shared.getToken() != nil,
// let notificationIdInt = Int32(notificationId) else {
// return
// }
//
// do {
// let result = try await APILayer.shared.markNotificationAsRead(notificationId: notificationIdInt)
//
// if result is ApiResultSuccess<Notification> {
// print(" Notification marked as read")
// } else if let error = result as? ApiResultError {
// print(" Failed to mark notification as read: \(error.message)")
// }
// } catch {
// print(" Error marking notification as read: \(error.localizedDescription)")
// }
// }
private func markNotificationAsRead(notificationId: String) async {
guard TokenStorage.shared.getToken() != nil,
let notificationIdInt = Int32(notificationId) else {
return
}
do {
let result = try await APILayer.shared.markNotificationAsRead(notificationId: notificationIdInt)
if result is ApiResultSuccess<ComposeApp.Notification> {
print("✅ Notification marked as read")
} else if let error = result as? ApiResultError {
print("❌ Failed to mark notification as read: \(error.message)")
}
} catch {
print("❌ Error marking notification as read: \(error.localizedDescription)")
}
}
// MARK: - Notification Preferences
@@ -206,3 +206,4 @@ class PushNotificationManager: NSObject, ObservableObject {
UIApplication.shared.applicationIconBadgeNumber = count
}
}