mirror of
https://github.com/Finb/Bark.git
synced 2025-12-08 21:36:01 +00:00
支持更新或撤回已发送的推送。
This commit is contained in:
parent
fcdcaceede
commit
1903797c8d
@ -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
|
||||
}
|
||||
|
||||
@ -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)"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user