您是否嘗試過使用getDeliveredNotifications(completionHandler:)
?你可以在例如顯示接收到的通知的控制器的viewDidLoad方法。
請注意,如果用戶在通知中心清除接收到的通知,這將不起作用。您必須按照您在評論中鏈接的問題的接受答案中所述的方式執行操作。
UNUserNotificationCenter.current().getDeliveredNotifications { notifications in
// notifications: An array of UNNotification objects representing the local
// and remote notifications of your app that have been delivered and are still
// visible in Notification Center. If none of your app’s notifications are
// visible in Notification Center, the array is empty.
// As said in the documentation, this closure may be executed in a background
// thread, so if you want to update your UI you'll need to do the following:
DispatchQueue.main.sync { /* or .async {} */
// update UI
}
}
來源
2017-09-13 09:10:42
nyg
@nyg我的問題是關於如何在應用程序終止時存儲通知。鏈接是關於處理通知在後臺狀態沒有終止狀態 –
基於這個問題的答案https://stackoverflow.com/questions/35058870/handling-push-notifications-when-app-is-ter-minated似乎沒有辦法存儲通知。但在whatsapp它正在工作。 –