Firebase消息传递不适用于“数据"iOS中的消息 [英] Firebase messaging not working for "data" messages in iOS

查看:56
本文介绍了Firebase消息传递不适用于“数据"iOS中的消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在iOS 9.3.5上运行的应用程序.当应用程序处于前台或后台时,我需要能够向其发送推送通知.我实际上不需要包含任何数据,我只需要对应用程序执行ping操作,这样它将"电话回家".因此,我不需要/不希望用户看到任何通知.

I have an app running on iOS 9.3.5. I need to be able to send a push notification to my app when it's in the foreground or background. I don't actually need to include any data, I just need to ping the app so it will "phone home". So I don't need/want the user to see any notifications.

由于该公司已经将Firebase用于其Android应用程序,因此我已在iOS应用程序中进行了设置.如果我使用有效负载中的 notification 键将消息发送到 https://fcm.googleapis.com/fcm/send ,它将在iPhone上接收.当我用 data 键尝试时,我什么也没得到.在这两种情况下,我都会从POST收到成功响应.我已经实现了以下回调:

Since the company is already using Firebase for their Android app, I've set that up in the iOS app. If I send a message to https://fcm.googleapis.com/fcm/send with the notification key in the payload, it's received on the iPhone. When I try it with the data key instead, I get nothing. In both cases I get a success response from the POST. I've implemented the follow callbacks:

application:didReceiveRemoteNotification:
userNotificationCenter:willPresentNotification:withCompletionHandler:
applicationReceivedRemoteMessage:(FIRMessagingRemoteMessage *)remoteMessage

使用 data 键发送消息时,不会调用任何一个.

None of those are called when sending a message with the data key.

这是我正在使用的有效载荷.

This is the payload I'm using.

{数据":{"message":"phonehome",},至":"xxxxx"}

{ "data": { "message": "phonehome", }, "to" : "xxxxx" }

经过更多测试后,当应用程序位于前台而不是后台时,我似乎收到了该消息.当我切换到前台时,将调用 application:didReceiveRemoteNotification:.

After doing some more testing it looks like I get that message when the app is in the foreground but not the background. When I switch to the foreground then application:didReceiveRemoteNotification: gets called.

添加了 content_available ,就可以了.谢谢!

Edit 2: Added content_available and that did the trick. Thanks!

{"to":"xxxx","content_available":true}

{ "to" : "xxxx", "content_available" : true }

推荐答案

如果没有样本有效负载,很难建议,但是,请尝试使用 priority 参数作为 high content_available true .

It's a little bit hard to suggest without a sample payload, However, do try to use the priority parameter as high or content_available to true.

这篇关于Firebase消息传递不适用于“数据"iOS中的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆