iOS 10 如何为远程通知设置 UNotificationContent threadIdentifier [英] iOS 10 How to set UNotificationContent threadIdentifier for remote notification
问题描述
TL;DR:需要在 APNs 通知负载 JSON 中设置什么键以对应于 UNNotificationContent
对象的 threadIdentifier
属性?例如"category"
键对应于 categoryIdentifier
属性.
iOS 10 引入了Notification Content Extension
,允许我们在通知展开时呈现视图控制器.
我们提供的视图控制器符合 UNNotificationContentExtension
协议,这要求我们实现 didReceive(_:)
方法.
此方法的文档包括以下段落:
<块引用>当您的视图控制器可见时,此方法可能会被多次调用.具体来说,当新通知到达时,其 threadIdentifier 值与已经显示的通知的线程标识符匹配时,它会再次调用.
threadIdentifier
属性可能在代码中设置用于本地通知,但我不知道如何为从服务器发送到 APNs 的远程通知设置它.
UNNotificationContent
文档在此处描述了该属性:http://developer.apple.com/reference/usernotifications/unnotificationcontent
以下 JSON 包含我尝试过的键("thread"
和 "thread-identifier"
):
<代码>{aps":{"alert" : "你好世界!",声音":默认",类别":示例类别",线程":示例线程",线程标识符":示例线程标识符"}自定义字段":一些值",}
我找不到 Apple 提供的任何有关如何设置的文档.有人可以帮忙吗?
我从 Apple 的一位联系人那里发现,填充此属性的正确键是 "thread-id"
键.>
所以发送给APNs的JSON如下:
<代码>{aps":{"alert" : "你好世界!",声音":默认",类别":示例类别",thread-id":我的谈话等等"}自定义字段":一些值",}
这会填充通过 notification.request.content.threadIdentifier
在您的通知内容扩展中访问的 UNNotificationContent
对象的 threadIdentifier
属性.>
通过设置这个"thread-id"
值,意味着你的内容扩展的didReceive(_:)
方法将被多次调用.首先是在最初扩展通知时,以及在具有相同 "thread-id"
值的新通知到达时再次.
我假设(希望)这将在 iOS 10 正式发布后添加到官方文档中.
TL;DR: What key needs to be set in the APNs notification payload JSON to correspond to the threadIdentifier
property of the UNNotificationContent
object? e.g. the "category"
key corresponds to the categoryIdentifier
property.
iOS 10 introduces the Notification Content Extension
allowing us to present a view controller when a notification is expanded.
The view controller that we provide conforms to the UNNotificationContentExtension
protocol, that requires us to implement the didReceive(_:)
method.
The documentation for this method includes the following paragraph:
This method may be called multiple times while your view controller is visible. Specifically, it is called again when a new notification arrives whose threadIdentifier value matches the thread identifier of the notification already being displayed.
The threadIdentifier
property may be set in code for local notifications, but I don't know how to set it for remote notifications that are sent from the server to APNs.
The UNNotificationContent
documentation describes the property here: http://developer.apple.com/reference/usernotifications/unnotificationcontent
The following JSON includes the keys I've tried ("thread"
and "thread-identifier"
):
{
"aps" : {
"alert" : "Hello World!",
"sound" : "default",
"category" : "example-category",
"thread" : "example-thread",
"thread-identifier" : "example-thread-identifier"
}
"custom-field" : "some value",
}
I can't find any documentation from Apple about how to set this. Can anyone help?
I discovered from a contact at Apple that the correct key to populate this property is the "thread-id"
key.
So the JSON sent to APNs is as follows:
{
"aps" : {
"alert" : "Hello World!",
"sound" : "default",
"category" : "example-category",
"thread-id" : "my conversation blah blah"
}
"custom-field" : "some value",
}
This populates the threadIdentifier
property of the UNNotificationContent
object accessible in your Notification Content Extension via notification.request.content.threadIdentifier
.
By setting this "thread-id"
value, it means that the didReceive(_:)
method of your content extension will be multiple times. First when expanding the notification initially, and again whenever a new notification arrives with the same "thread-id"
value.
I assume (hope) this will be added to the official documentation once iOS 10 is officially released.
这篇关于iOS 10 如何为远程通知设置 UNotificationContent threadIdentifier的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!