iOS 10如何为远程通知设置UNotificationContent threadIdentifier

TL; DR:需要在APNs通知有效负载JSON中设置哪个密钥才能对应UNNotificationContent对象的threadIdentifier属性? 例如, "category"键对应于categoryIdentifier属性。


iOS 10引入了Notification Content Extension允许我们在Notification Content Extension通知时呈现视图控制器。

我们提供的视图控制器符合UNNotificationContentExtension协议,该协议要求我们实现UNNotificationContentExtension didReceive(_:)方法。

该方法的文档包括以下段落:

当您的视图控制器可见时,可以多次调用此方法。 具体地说,当新的通知到达时,再次调用它,其threadIdentifier值与已经显示的通知的线程标识符匹配。

threadIdentifier属性可以在本地通知的代码中设置,但我不知道如何为从服务器发送到APN的远程通知设置它。

UNNotificationContent文档描述了此处的属性: http : //developer.apple.com/reference/usernotifications/unnotificationcontent

以下JSON包括我尝试过的密钥( "thread""thread-identifier" ):

 { "aps" : { "alert" : "Hello World!", "sound" : "default", "category" : "example-category", "thread" : "example-thread", "thread-identifier" : "example-thread-identifier" } "custom-field" : "some value", } 

我找不到Apple的任何关于如何设置它的文档。 有人可以帮忙吗?

我在Apple的一个联系人中发现,填充此属性的正确密钥是"thread-id"密钥。

所以发送给APN的JSON如下:

 { "aps" : { "alert" : "Hello World!", "sound" : "default", "category" : "example-category", "thread-id" : "my conversation blah blah" } "custom-field" : "some value", } 

这将通过threadIdentifier填充您的Notification Content Extension中可访问的UNNotificationContent对象的threadIdentifier属性。

通过设置此"thread-id"值,这意味着内容扩展的didReceive(_:)方法将多次。 首先在最初扩展通知时,并且每当新通知到达时具有相同的"thread-id"值。

我假设(希望)一旦iOS 10正式发布,这将被添加到官方文档中。