iOS "thread-id" 不分组推送通知
iOS "thread-id" doesn't group push notifications
thread-id
| string
| When displaying notifications, the system visually groups notifications with the same thread identifier together.
For remote notifications, the value of the threadIdentifier property is set to the value of this request header.
我们的推送通知负载:
{
aps = {
alert = {
body = "Leeroy J asked you: Test Push Notification";
};
badge = 12;
sound = default;
"thread-id" = 9150;
};
n = "6kQ/0x6556";
r = 9150;
}
{
aps = {
alert = {
body = "Leeroy J re: Test Push Notification";
};
badge = 13;
sound = default;
"thread-id" = 9150;
};
n = "6l8/0x6582";
p = 7197;
r = 9150;
}
消息中心的外观如下:
我希望它们在视觉上与其他通知不同...要么是那样,要么是当其他通知介于两者之间时组合在一起。在我们的测试中,两者都不是。
我做错了什么?还是我误解了这个功能?
很遗憾,您无法免费获得此服务。您需要创建一个具有相同线程 ID 的 Notifictation UI extension, and implement your own UI(in this case it's a conversation UI), and update the UI when receive new notification。
编辑:这可能不是正确答案,请查看更全面的答案。
我在 Firebase 未使用 apns-collapse-id 时遇到了这个问题。我如何解决它是使用密钥而不是证书。您可以在 developer.apple.com 中的证书下方找到密钥。它现在使用一个 "row" 通知并将组中的最后一个通知放入该行。替换内容等高级功能需要使用通知 ui 扩展。
说改用 apns-collapse-id
你不需要:
apns-collapse-id
NotificationContentExtension
文档中从来没有提到您需要它们。只是他们相关.
解决方案:
对我来说,它开箱即用。只是 iOS 不会立即 将通知呈现到组中。
- 使用
thread-id
s 发送通知
- 然后等等。让您的 iPhone/iPad 锁定屏幕关闭。 (我的被锁了)。
- 然后再发一条消息
- 如果还是不行,请耐心等待再试一次。
然后突然间它开始分组并按预期工作!!!
要进行堆叠,您需要一些通知。如果 space 太多,更可能在 iPad 上,则需要更多才能开始堆叠它们。还要确保您已将通知分组设置正确设置为 'Automatic'
thread-id
的其他用法:
thread-id
的用法还有另一个用途,最好在消息传递应用程序中进行解释。想想 iMessage。
- 您收到朋友的消息。
- 你长按通知
- 它将打开一个弹出窗口,您可以在其中从 contentExtension
中聊天
- 如果您的朋友发送更多消息,那么您的 content-extension 的
didReceiveNotification
将不断接到电话。它得到
打来电话,以便您更新对话。
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 method is called on the
main thread of your notification content app extension.
reference to didReceive(_:)
docs
有关此内容的更多信息,请参阅 this answer
总结
Grouping 与 为单个 thread-id
连续回调您的 contentExtension 是使用 thread-id
!
什么是 apns-collapse-id
?
如果您发送了通知并且它有点需要 correction/update,则使用它。例如,您是华盛顿邮报,有人刚刚赢得总统职位。
您首先发送一个标题为 'Albert Bori has won 2020 election!!' 的通知,其中 body 为: 此消息将很快更新...
然后 3 分钟后,您获得更多信息,他在 40 个州获胜,在 10 个州失败,从而赢得了选举。因此您更新了 body。然后你会得到更多关于确切票数的信息。所以你再次更新 body 。您可以不断更新消息 而不会提醒 (没有声音,也没有新横幅。它只会在通知中心更新)更新的用户。
仅当用户已经 dismissed/viewed 通知时,具有相同 apns-collapse-id
的通知才会 alert/notify 用户。不是用来分组的,是用来合并的!
请注意,thread-id
类型必须是字符串,而在您的负载中它是整数。开箱即用。
thread-id
|string
| When displaying notifications, the system visually groups notifications with the same thread identifier together. For remote notifications, the value of the threadIdentifier property is set to the value of this request header.
我们的推送通知负载:
{
aps = {
alert = {
body = "Leeroy J asked you: Test Push Notification";
};
badge = 12;
sound = default;
"thread-id" = 9150;
};
n = "6kQ/0x6556";
r = 9150;
}
{
aps = {
alert = {
body = "Leeroy J re: Test Push Notification";
};
badge = 13;
sound = default;
"thread-id" = 9150;
};
n = "6l8/0x6582";
p = 7197;
r = 9150;
}
消息中心的外观如下:
我希望它们在视觉上与其他通知不同...要么是那样,要么是当其他通知介于两者之间时组合在一起。在我们的测试中,两者都不是。
我做错了什么?还是我误解了这个功能?
很遗憾,您无法免费获得此服务。您需要创建一个具有相同线程 ID 的 Notifictation UI extension, and implement your own UI(in this case it's a conversation UI), and update the UI when receive new notification。
编辑:这可能不是正确答案,请查看更全面的答案
我在 Firebase 未使用 apns-collapse-id 时遇到了这个问题。我如何解决它是使用密钥而不是证书。您可以在 developer.apple.com 中的证书下方找到密钥。它现在使用一个 "row" 通知并将组中的最后一个通知放入该行。替换内容等高级功能需要使用通知 ui 扩展。
说改用 apns-collapse-id
你不需要:
apns-collapse-id
NotificationContentExtension
文档中从来没有提到您需要它们。只是他们相关.
解决方案:
对我来说,它开箱即用。只是 iOS 不会立即 将通知呈现到组中。
- 使用
thread-id
s 发送通知
- 然后等等。让您的 iPhone/iPad 锁定屏幕关闭。 (我的被锁了)。
- 然后再发一条消息
- 如果还是不行,请耐心等待再试一次。
然后突然间它开始分组并按预期工作!!!
要进行堆叠,您需要一些通知。如果 space 太多,更可能在 iPad 上,则需要更多才能开始堆叠它们。还要确保您已将通知分组设置正确设置为 'Automatic'
thread-id
的其他用法:
thread-id
的用法还有另一个用途,最好在消息传递应用程序中进行解释。想想 iMessage。
- 您收到朋友的消息。
- 你长按通知
- 它将打开一个弹出窗口,您可以在其中从 contentExtension 中聊天
- 如果您的朋友发送更多消息,那么您的 content-extension 的
didReceiveNotification
将不断接到电话。它得到 打来电话,以便您更新对话。
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 method is called on the main thread of your notification content app extension.
reference to
didReceive(_:)
docs
有关此内容的更多信息,请参阅 this answer
总结
Grouping 与 为单个 thread-id
连续回调您的 contentExtension 是使用 thread-id
!
什么是 apns-collapse-id
?
如果您发送了通知并且它有点需要 correction/update,则使用它。例如,您是华盛顿邮报,有人刚刚赢得总统职位。
您首先发送一个标题为 'Albert Bori has won 2020 election!!' 的通知,其中 body 为: 此消息将很快更新...
然后 3 分钟后,您获得更多信息,他在 40 个州获胜,在 10 个州失败,从而赢得了选举。因此您更新了 body。然后你会得到更多关于确切票数的信息。所以你再次更新 body 。您可以不断更新消息 而不会提醒 (没有声音,也没有新横幅。它只会在通知中心更新)更新的用户。
仅当用户已经 dismissed/viewed 通知时,具有相同 apns-collapse-id
的通知才会 alert/notify 用户。不是用来分组的,是用来合并的!
请注意,thread-id
类型必须是字符串,而在您的负载中它是整数。开箱即用。