ios - 如何在 iOS 中调试后台通知?
问题描述
我正在尝试在 iOS 上调试后台推送通知,更具体地说,将断点设置到应该处理通知以使用自定义逻辑配置国际化内容的代码中。
我在我的 AppDelegateuserNotificationCenter(_:willPresent:withCompletionHandler:)
和userNotificationCenter(_:didReceive:withCompletionHandler:)
.
而且我还创建了一个通知服务扩展并为其添加了一个断点,didReceive(_:withContentHandler:)
因为我想改变通知的内容。
当我发送以下有效负载并且我的应用程序位于前台时,中的断点userNotificationCenter(_:willPresent:withCompletionHandler:)
被命中并且一切正常:
{
"aps" : {
"badge" : 1012,
"category" : "GENERIC_MESSAGE",
"mutable-content" : 1
},
"translations" : [
{
"LanguageCode" : "fr",
"Title" : "Aimant détaché",
"Body" : "L'aimant du capteur 002F51AB, associé à l'outil HT-1225 Hitachi Tas, a été détaché."
},
{
"LanguageCode" : "en",
"Body" : "The magnet of the tag 002F51AB, link to tool HT-1225 Hitachi Tas, was detached.",
"Title" : "Magnet detached"
},
{
"LanguageCode" : "nl",
"Body" : "De magneet van de tag 002F51AB, gelinkt aan het gereedschap HT-1225 Hitachi Tas, is losgekoppeld.",
"Title" : "Magneet losgekoppeld"
}
],
"messageId" : "90073ebb-ce51-ea11-a94c-000d3a213771"
}
但是,如果应用程序在后台并且我发送完全相同的通知,我不会在userNotificationCenter(_:didReceive:withCompletionHandler:)
. 当我运行通知服务扩展时,同样的事情,我没有受到打击didReceive(_:withContentHandler:)
我是不是忘记了什么?是因为我的通知负载没有 aps 警报字段吗?
解决方案
我想通了:当我在推送通知中添加警报字段时,即使使用虚拟字符串,它也会被转发到我的通知服务。否则不会。
推荐阅读
- jquery - 使用 jquery 通过类名获取元素的高度
- javascript - 为什么 v-dialog 会重置另一个元素的可见性切换?
- deep-learning - Pytorch 迭代数据加载器两次
- powershell - Powershell 将所有输出流重定向到文件并将错误重定向到控制台
- javascript - 如何在 firebase 中编写复合查询?
- python - 如何创建函数列表,然后在另一个函数中将其用作可调用函数?
- python-3.x - TLS/SSL 套接字 python 服务器
- javascript - 反应中嵌套对象的唯一键
- sql - 我可以从一个表到另一个表有两个外键,以获得两列字段吗?
- python - 验证时将 Row 转换为 json 错误