支持更新或撤回已发送的推送。

This commit is contained in:
Fin 2025-07-17 17:42:18 +08:00
parent fcdcaceede
commit 1903797c8d
3 changed files with 28 additions and 5 deletions

View File

@ -101,7 +101,26 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
}
notificatonHandler(userInfo: response.notification.request.content.userInfo)
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
guard let delete = userInfo["delete"] as? String, delete == "1", let id = userInfo["id"] as? String else {
completionHandler(.noData)
return
}
//
UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: [id])
//
if let realm = try? Realm(),
let message = realm.objects(Message.self).filter("id == %@", id).first
{
try? realm.write {
realm.delete(message)
}
}
completionHandler(.newData)
}
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification) async -> UNNotificationPresentationOptions {
return .alert
}

View File

@ -1,5 +1,5 @@
//
// MessageTableViewCellViewModel.swift
// MessageSection.swift
// Bark
//
// Created by huangfeng on 2020/11/21.
@ -51,9 +51,9 @@ extension MessageListCellItem: IdentifiableType {
var identity: String {
switch self {
case .message(let model):
return "list_\(model.id)"
return "list_\(model.id)_\(model.createDate?.timeInterval ?? 0)"
case .messageGroup(_, _, let messages):
return "group_\(messages.first?.group ?? NSLocalizedString("Default"))"
return "group_\(messages.first?.group ?? NSLocalizedString("Default"))_\(messages.first?.createDate?.timeInterval ?? 0)"
}
}
}

View File

@ -31,9 +31,13 @@ class ArchiveProcessor: NotificationContentProcessor {
let url = userInfo["url"] as? String
let group = userInfo["group"] as? String
let image = userInfo["image"] as? String
let id = userInfo["id"] as? String
try? realm?.write {
let message = Message()
if let id, !id.isEmpty {
message.id = id
}
message.title = title
message.subtitle = subtitle
message.body = body
@ -41,7 +45,7 @@ class ArchiveProcessor: NotificationContentProcessor {
message.image = image
message.group = group
message.createDate = Date()
realm?.add(message)
realm?.add(message, update: .all)
}
}
return bestAttemptContent