ios push notifications
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user