Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何获取所有挂起的远程通知的数组?_Ios_Iphone - Fatal编程技术网

Ios 如何获取所有挂起的远程通知的数组?

Ios 如何获取所有挂起的远程通知的数组?,ios,iphone,Ios,Iphone,情景: 我的应用程序已关闭(不在后台) 我收到了不止一个远程通知 我单击应用程序图标(而不是远程通知) 如何获取接收到的远程通知的JSON有效负载数组(超过1个) 提前感谢。不幸的是,这是不可能的。 您将只接收有关用于打开应用程序的通知的信息。如果用户打开你的应用程序,而你有多个通知,你将无法从应用程序中检索所有通知 仅存储特定应用程序的一个最近通知。如果在设备脱机时发送多个通知,则每个新通知都会导致放弃先前的通知 APNs 服务质量 Apple推送通知服务包括一个默认的服务质量(QoS)组件,

情景:

  • 我的应用程序已关闭(不在后台)
  • 我收到了不止一个远程通知
  • 我单击应用程序图标(而不是远程通知)
  • 如何获取接收到的远程通知的
    JSON
    有效负载数组(超过1个)


    提前感谢。

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

    您将只接收有关用于打开应用程序的通知的信息。如果用户打开你的应用程序,而你有多个通知,你将无法从应用程序中检索所有通知

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

    APNs

    服务质量

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

    如果APNs试图发送通知,但设备处于脱机状态,则通知将存储一段有限的时间,并在可用时发送给设备

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

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

    iOS


    您只能在最后一次远程通知时保持

    ,因为iOS 10是可能的

        [[UNUserNotificationCenter currentNotificationCenter] getDeliveredNotificationsWithCompletionHandler:^(NSArray<UNNotification *> * _Nonnull notifications) {
        NSLog(@"msg getDeliveredNotificationsWithCompletionHandler count %lu", [notifications count]);
           }];
    
    [[UNUserNotificationCenter currentNotificationCenter]getDeliveredNotificationsWithCompletionHandler:^(NSArray*\u非空通知){
    NSLog(@“msg getDeliveredNotificationsWithCompletionHandler计数%lu”,[notifications计数]);
    }];
    
    你可以这样做

    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()
            }
        }
    

    这很糟糕,但事实就是这样:(你可以使用“UNUserNotificationCenter.current().getDeliveredNotifications”方法来获取发送到iPhone的应用程序的所有通知