我在didReceive
、willPresent
和getDeliverredNotifications
函数上达到了UINotification
值。但我无法达到didReceiveRemoteNotification
中的通知值。我想要达到通知,因为通知值具有标识符和日期信息。我将通知数据存储到设备,我需要该信息。
extension AppDelegate: UNUserNotificationCenterDelegate {
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void){
let userInfo = response.notification.request.content.userInfo
let id = response.notification.request.identifier
let date = response.notification.date
completionHandler()
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
guard let aps = userInfo["aps"] as? [String: AnyObject] else {
completionHandler(.failed)
return
}
}
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification) async -> UNNotificationPresentationOptions {
let userInfo = notification.request.content.userInfo
let id = notification.request.identifier
let date = notification.date
return [[.banner, .badge, .list, .sound]]
}
}
我尝试在didReceiveRemoteNotification
中获取通知数据,但无法获取。
1条答案
按热度按时间tvz2xvvm1#
在服务器端创建推送通知时,将此数据放入didReceiveRemoteNotification的userInfo中获取唯一id和日期,可以在服务器端获取当前日期或在didReceiveRemoteNotification中调用Date()。