【发布时间】:2019-01-06 07:51:52
【问题描述】:
对不起,如果这是一个愚蠢的问题,我是第一次使用 APN 设置 Firebase。我正在使用 iOS 应用程序在 Swift 中工作,并且我有 apns 消息在没有 Firebase 的情况下单独工作——因此在后台和运行应用程序时在设备上接收到远程推送通知。我可以使用这个工具https://github.com/noodlewerk/NWPusher通过发送这个json blob作为例子来成功发送沙箱和生产apns证书的通知:
{"aps":{"alert":"Testing","badge":1,"sound":"default"}}
但是,现在我正在尝试合并 Firebase,但在 iOS 设备上却没有获得相同的行为。
我设置了 Firebase 消息传递,该应用使用 "shouldEstablishDirectChannel = true" 打印远程消息,但从未收到 APNs(将此设置为 false,则设备不打印任何内容)。设备上没有收到推送通知。我不相信 APN 被正确映射到 Firebase 消息,因为我无法让设备以与 NWPusher 严格 APN 沙盒和生产证书相同的方式显示推送通知。 Firebase 应用程序控制台具有应用程序的 .p12 apns 证书(对于不涉及 firebase 的 apns 可以正常工作)
这是我尝试发送给https://fcm.googleapis.com/fcm/send的示例请求
{
"to" : "eqkeyhereinifnbe",
"collapse_key" : "type_a",
"data" : {
"body" : "Notification",
"title": "testing",
"key_1" : "Data for key one",
"key_2" : "Hello Meowww",
}
}
API 返回成功响应:
{
"multicast_id": 634054476369,
"success": 1,
"failure": 0,
"canonical_ids": 0,
"results": [
{
"message_id": "0:15329261441bfd36cccfb49c"
}
]
}
在 iOS 应用的 AppDelegate 中:
func messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage) {
print("Received data message: \(remoteMessage.appData)!")
}
^从设备上的 api 成功打印消息:
收到数据消息:[AnyHashable("collapse_key"): type_a, AnyHashable("key_1"): 键一的数据 AnyHashable("from"): 9861340, AnyHashable("key_2"): 你好 Meowww, AnyHashable("body"): 通知, AnyHashable("title"): 测试]!
但是,收到的这条消息不会对 iOS 设备执行任何 APNs 通知魔法。我尝试将相同的 json blob 发送到在 NWPusher 中运行良好的 Firebase API:{"aps":{"alert":"Testing","badge":1,"sound":"default"}},但设备不显示通知。为什么?如何解决此问题以使 Firebase 发送相同的 APNs 通知以在设备上显示通知?
【问题讨论】:
标签: swift firebase push-notification apple-push-notifications firebase-cloud-messaging