如何获取所有待处理远程通知的数组?

时间:2014-03-01 09:16:55

标签: ios iphone

情景:

  1. 我的申请已关闭(不在后台)。
  2. 我收到了多个远程通知。
  3. 我点击了应用图标(不是远程通知)。
  4. 如何为收到的远程通知(超过1)获取JSON有效负载数组。

    提前致谢。

4 个答案:

答案 0 :(得分:4)

不幸的是,这是不可能的。

会收到有关用于打开您的应用的通知的信息。如果用户打开您的应用,并且您有多个通知,则无法从应用中检索所有这些通知。

仅存储特定应用程序的最近通知。如果在设备离线时发送了多个通知,则每个新通知都会导致先前通知被丢弃。

Apple Push Notification Service

答案 1 :(得分:3)

<强>的APN

  

服务质量

     

Apple推送通知服务包括执行存储转发功能的默认服务质量(QoS)组件。

     

如果APN尝试发送通知但设备处于离线状态,则通知会在一段有限的时间内存储,并在设备可用时传送给设备。

     

仅存储特定应用程序的最近通知。如果在设备脱机时发送多个通知,则每个新通知都会导致先前通知被丢弃。仅保留最新通知的这种行为称为合并通知。

     

如果设备长时间处于脱机状态,则会丢弃为其存储的所有通知。

Source

<强>的iOS

您可以暂停仅限最后一次远程通知

答案 2 :(得分:2)

在iOS 10上可以实现

    [[UNUserNotificationCenter currentNotificationCenter] getDeliveredNotificationsWithCompletionHandler:^(NSArray<UNNotification *> * _Nonnull notifications) {
    NSLog(@"msg getDeliveredNotificationsWithCompletionHandler count %lu", [notifications count]);
       }];

答案 3 :(得分:0)

您可以这样做

func getAllDeleveredPendingNotifications() {
        let center = UNUserNotificationCenter.current()
        center.getDeliveredNotifications { (notifications) in
            print("pending notifications \(notifications)")
            for info in notifications {
                let userInfo = info.request.content.userInfo
                print("UserInfo is  \(userInfo)")
            }
            self.removeAllPendingNotification()
        }
    }