iOS更新推送内容扩展 [英] iOS update push in content extension
问题描述
iMessage在屏幕上显示丰富推送时会进行更新.您可以看到什么是用户现在输入RIGHT,消息将被添加到您的对话中.
iMessage updates the rich push when it's on the screen. You can see what is user is typing RIGHT NOW, and message will be added to your conversation.
所以问题是:当我已经在查看已打开的丰富推送时,如何捕获新的推送通知? UNNotificationContentExtension 中是否有任何事件可以捕获新事件并更新视图?我唯一知道的是:
So the question is: how i can catch new push notification, when i'm already looking at opened rich push? Is there any event in UNNotificationContentExtension to catch the new one and update view? The only one i know is:
- (void)didReceiveNotification:(UNNotification *)notification
,但是只有在您第一次打开推送时才会触发
but it is triggered only when you open the push first time
在UNNotificationContentExtension协议中发现了这一点:
Found that in UNNotificationContentExtension protocol:
// This will be called to send the notification to be displayed by
// the extension. If the extension is being displayed and more related
// notifications arrive (eg. more messages for the same conversation)
// the same method will be called for each new notification.
- (void)didReceiveNotification:(UNNotification *)notification;
所以它应该可以工作,但是我还是无法捕捉到此事件.也许我需要以某种方式使新通知与当前显示相关"?
So it should work but i can't catch this event anyway. Maybe i need somehow to make new notification "related" to currently displayed?
推荐答案
弄清楚问题出在哪里.
Apple文档:
显示通知时,系统以可视方式进行分组 具有相同线程标识符的通知.对于远程 通知,此属性的值设置为 aps字典中的thread-id键.
When displaying notifications, the system visually groups notifications with the same thread identifier together. For remote notifications, the value of this property is set to the value of the thread-id key in the aps dictionary.
在将密钥"thread-id"添加到aps字典后,此功能现在可以正确接收事件了
After adding key "thread-id" to aps dictionary, this func now receiving events correctly
- (void)didReceiveNotification:(UNNotification *)notification;
这篇关于iOS更新推送内容扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!