首页 文章

APN与Firebase分开运行,但无法在FCM中使用通知

提问于
浏览
0

很抱歉,如果这是一个愚蠢的问题,我是第一次使用APN设置Firebase . 我正在使用iOS应用程序在Swift中工作,并且我在没有Firebase的情况下单独使用apns消息 - 因此在后台和运行应用程序时在设备上接收远程推送通知 . 我可以使用此工具https://github.com/noodlewerk/NWPusher通过发送此json blob作为示例成功发送有关Sandbox和Production apns证书的通知:

{"aps":{"alert":"Testing","badge":1,"sound":"default"}}

但是,现在我正在尝试合并Firebase,而不是在iOS设备上获得相同的行为 .

我有Firebase消息设置,应用程序使用 "shouldEstablishDirectChannel = true" 打印远程消息但是从未收到过APN(设置为false,然后设备不相信正在为Firebase消息正确映射APN,因为我无法让设备显示推送通知同样我可以使用NWPusher严格按照APNs Sandbox和Production证书.Firebase app控制台有应用程序的.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”):Hello Meowww,AnyHashable(“body” “):通知,AnyHashable(” Headers “):测试]!

但是,此收到的消息不会对iOS设备执行任何APN通知魔法 . 我尝试将相同的json blob发送到在NWPusher中正常工作的Firebase API: {"aps":{"alert":"Testing","badge":1,"sound":"default"}} ,但设备不显示通知 . 为什么?如何解决此问题,以使Firebase发送相同的APN通知以在设备上显示通知?

1 回答

  • 0

    我只需要用“message”和“data”对象编写请求,如下所示:

    {
        "to" : "aTokenHerefonsfondfodnfdofndf",
        "collapse_key" : "type_a",
        "notification":{
          "title":"Notification title test",
          "body":"It worked body"
        },
        "data" : {
            "body" : "Notification",
            "title": "testing",
            "key_1" : "Data for key 1",
            "key_2" : "Hello Meowww"
        }
    }
    

相关问题