iOS 10如何为远程通知设置UNotificationContent threadIdentifier [英] iOS 10 How to set UNotificationContent threadIdentifier for remote notification

查看:326
本文介绍了iOS 10如何为远程通知设置UNotificationContent threadIdentifier的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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引入了通知内容扩展,允许我们在扩展通知时显示视图控制器。

iOS 10 introduces the Notification Content Extension allowing us to present a view controller when a notification is expanded.

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

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:

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

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.

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

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.

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

The UNNotificationContent documentation describes the property here: http://developer.apple.com/reference/usernotifications/unnotificationcontent

以下JSON包含我尝试过的密钥(threadthread-identifier):

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",
}

我找不到Apple提供的有关如何设置此文件的任何文档。任何人都可以帮忙吗?

I can't find any documentation from Apple about how to set this. Can anyone help?

推荐答案

我从Apple的联系人那里发现填充这个属性的正确密钥是thread-id key。

I discovered from a contact at Apple that the correct key to populate this property is the "thread-id" key.

因此发送给APN的JSON如下:

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",
}

这会填充 threadIdentifier 通过 notification.request.content.threadIdentifier 在您的通知内容扩展中可访问的 UNNotificationContent 对象的属性。

This populates the threadIdentifier property of the UNNotificationContent object accessible in your Notification Content Extension via notification.request.content.threadIdentifier.

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

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.

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

I assume (hope) this will be added to the official documentation once iOS 10 is officially released.

这篇关于iOS 10如何为远程通知设置UNotificationContent threadIdentifier的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆