【发布时间】:2019-04-23 15:59:51
【问题描述】:
当我打开应用程序时,我需要阅读在手机处于非活动状态或后台模式时收到的所有推送通知。 “didReceiveRemoteNotification”方法只在通知点击时调用,我想在不点击的情况下阅读通知
【问题讨论】:
标签: ios swift firebase push-notification
当我打开应用程序时,我需要阅读在手机处于非活动状态或后台模式时收到的所有推送通知。 “didReceiveRemoteNotification”方法只在通知点击时调用,我想在不点击的情况下阅读通知
【问题讨论】:
标签: ios swift firebase push-notification
返回仍显示在通知中心的应用通知列表。
let center = UNUserNotificationCenter.current()
center.getDeliveredNotifications(completionHandler: { (notificationRequests) in
for x in notificationRequests {
print(x.request.content.body)
}
})
另一种方式
这些都是远程推送通知,由您的后端服务器通过Apple云服务器推送。最好向您的服务器请求检索所有推送通知有效负载以响应并显示给您的客户端,在这里您可以根据需要进行管理。
然后你从通知托盘中清除通知......就像这样。
application.applicationIconBadgeNumber = 0 // For Clear Badge Counts
let center = UNUserNotificationCenter.current()
center.removeAllDeliveredNotifications() // To remove all delivered notifications
center.removeAllPendingNotificationRequests()
【讨论】:
didReceiveRemoteNotification 在用户点击通知之前不会被调用。