【问题标题】:Get received PUSH notification list without tap on the notification无需点击通知即可获得收到的推送通知列表
【发布时间】:2019-04-23 15:59:51
【问题描述】:

当我打开应用程序时,我需要阅读在手机处于非活动状态或后台模式时收到的所有推送通知。 “didReceiveRemoteNotification”方法只在通知点击时调用,我想在不点击的情况下阅读通知

【问题讨论】:

    标签: ios swift firebase push-notification


    【解决方案1】:

    返回仍显示在通知中心的应用通知列表。

    let center = UNUserNotificationCenter.current()
    center.getDeliveredNotifications(completionHandler: { (notificationRequests) in
                for x in notificationRequests {
                print(x.request.content.body)
            }
            })
    

    这是苹果文档链接 https://developer.apple.com/documentation/usernotifications/unusernotificationcenter/1649520-getdeliverednotifications

    另一种方式

    这些都是远程推送通知,由您的后端服务器通过Apple云服务器推送。最好向您的服务器请求检索所有推送通知有效负载以响应并显示给您的客户端,在这里您可以根据需要进行管理。

    然后你从通知托盘中清除通知......就像这样。

    application.applicationIconBadgeNumber = 0 // For Clear Badge Counts
    let center = UNUserNotificationCenter.current()
    center.removeAllDeliveredNotifications() // To remove all delivered notifications
    center.removeAllPendingNotificationRequests() 
    

    【讨论】:

    • 啊,我会试试的,非常感谢您的回答,但是没有任何方法可以循环所有收到的推送通知
    • didReceiveRemoteNotification 在用户点击通知之前不会被调用。
    • @Nithaparan 我已经更新了我的答案.. 你能试试其他方法吗。
    • @Nithaparan.. 你能给我们反馈吗?此解决方案是否有效。
    • @SachinVsSachin getDeliveredNotifications(completionHandler:) 工作。非常感谢
    猜你喜欢
    • 1970-01-01
    • 2020-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多