I'm having a weird issue with FCM, specifically when sending silent push notifications to iOS devices.
Here is the JSON we were sending on the HTTP request to Firebase four days ago:
{
"to": "<firebase token>",
"content_available": true
}
Today, that JSON no longer works. Based on this StackOverflow response, I tried adding the sound property like so:
{
"to": "<firebase token>",
"content_available": true,
"notification": {
"sound": ""
}
}
Now this works. I shouldn't need to specify an empty sound property on this in order to get it working.
For context, these are things that do work:
Sending non-silent push notifications through Firebase Cloud Messaging
Sending silent and non-silent push notifications directly through APNs
Anyone have an idea on what's going on?
Related
We have a Django backend server using pyfcm to deliver Notifications throgh Firebase Cloud Messaging (FCM). I just updated to the today released Version 1.3.0. I want to send a notification using the loc-key and loc-args parameters so it can be displayed in the language the user is using on his phone. The notification reaches the device, it vibrates and makes the default sound for a new notification, but it will not displayed. It just happens nothing except for the sound and vibration.
This is the payload generated by the server which is sent to the fcm endpoint:
{
"notification": {
"loc-args": ["Demo (#demo)"],
"loc-key": "notification-follow",
"sound": "Default"
},
"priority": "high",
"to": "..."
}
On the client side, this is what is received by the phone:
[
AnyHashable("gcm.message_id"):0:1496257581534217 %f910cc44f910cc44,
AnyHashable("aps"):{
category = profile;
sound = Default;
},
AnyHashable("gcm.notification.alert"):{
"title-loc-key":" notification-follow",
"title-loc-args":[
"Demo (#demo)"
]
}
]
Is there anything I have to do before the message is displaying? Sending the message without the loc-key and loc-args but with message-body presents the notificaion on the device. Maybe the payload is wrong? How should it look like to do what I want?
The key, notification-follow in this case, is listed and translated in the Localizable.strings files in any available language.
Ok, problem solved. It was pyFCM. I thought it would be an error with this library, so the developer pseudo-fixed it. But it worked properly, and now it doesn't work anymore. The trick is to give body_loc_args an array, otherwise it will give you an InvalidParameters error.
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.
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
None of those are called when sending a message with the data key.
Edit:
This is the payload I'm using.
{ "data": {
"message": "phonehome",
},
"to" : "xxxxx"
}
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.
Edit 2: Added content_available and that did the trick. Thanks!
{ "to" : "xxxx", "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.
I'm using Google's Firebase Cloud Messaging to send push-notifications to my iOS and Android applications. The push-notifications sent through the Cloud Messaging console work just as intended, however when I send a push-notification through the API, the iOS application only receives it when in foreground. On Android, it is working correctly (both in foreground and background).
Reading the documentation, the iOS system would then transfer the "notification" object to the system tray, as intended, showing the "body" message. However, this is not working.
Here's the content of the JSON I'm sending:
{
"notification":
{
"body": "This a test notification"
},
"to":"eQ5tiy0cMZ8:APA91bE4CCjDXEJxEIRxKY18pXMMGUBqY1OKJFhVbR-pNhvQjJuhPcc7pXa..."
}
Did anyone have similar problems using Firebase Cloud Messaging recently? Thank you.
I managed to fix the problem thanks to this answer: https://stackoverflow.com/a/37550067/516338
Basically, although NOT in the documents, you have to set the "priority" field to "high" on iOS, like this:
{
"to": "cHPpZ_s14EA:APA91bG56znW...",
"priority": "high",
"notification" : {
"body" : "hello!",
"title": "afruz",
"sound": "default"
}
}
I have a question.For iOS,Can we send both "data" and "notification" in the payload?I was getting the notification when only "notification" was sent to the GCM.When I added both,I am not getting any notification.My question is,What should be the payload if I want to get update on both iOS and android devices?
current payload :
{
"to":"/topics/testTopic",
"content_available":true,
"priority":"high",
"notification": {
"body":"Test Message",
"title":"test"
},
"data": {
"title": "Title.D Mixed JSON",
"body": "Content.D Mixed JSON",
"productId" : "1"
}
}
Your payload is fine, there is no reason that you should not be getting it. But there are some differences between those two.
Difference between "notification" and "data" is documented in official documentation: https://developers.google.com/cloud-messaging/concept-options
Use notifications when you want GCM to handle displaying a notification on your client app’s behalf. Use data messages when you want your app to handle the display or process the messages on your Android client app, or if you want to send messages to iOS devices when there is a direct GCM connection
So, for you hybrid messages that you want to send it is important to know if your app is in the background or in the foreground:
When in the background, apps receive the notification payload in the notification tray, and only handle the data payload when the user taps on the notification.
When in the foreground, your app receives a bundle with both payloads available.
Another reason for not receiving push notifications is that you have not assigned delivery priority. There are two options normal and high.
High
High priority. GCM attempts to deliver high priority messages immediately, allowing the GCM service to wake a sleeping device when possible and open a network connection to your app server
Normal
Normal priority. This is the default priority for message delivery. Normal priority messages won't open network connections on a sleeping device, and their delivery may be delayed to conserve battery
Try to set "priority" : "high" right before "notification" in your payload.
It's not Allowed to duplicate the content of "notification" and "data", you can read the data inside the "notification" when the user tap on the notification, the following JSON should work with you.
{
"to":"/topics/testTopic",
"content_available":true,
"priority":"high",
"notification": {
"body":"Test Message",
"title":"test"
},
"data": {
"productId" : "1"
}
}
I'm subscribing to a gcm topic with my iOS device. In googles documentation (https://developers.google.com/cloud-messaging/topic-messaging) they say that the http-post should look like this:
https://gcm-http.googleapis.com/gcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
{ "to": "/topics/foo-bar", "data": {
"message": "This is a GCM Topic Message!", } }
Using this doesn't get my iOS device notified. I have to include the content_available header and it's value HAS to be true. Otherwise, iOS device will not get notified.
Also, in the documentation, they say that I should look for the "from" in the notification that is sent to the iOS device, but that field is never there.
Am I missing something?