I'm currently trying out the google cloud messaging service with its sample application "Guestbook." https://developers.google.com/cloud/samples/mbs/
I'm attempting to send notifications that should appear as a simple "hello" toast on screen for about 5 seconds.Doing this from the project settings page (pictured here)works.Perhaps i've misinterpreted what this for.
However my attempts to do it manually via fiddler2 cause the guestbook client application to crash instead of making the intended toast flash up onscreen.
Here is an example of the POST request i used to attempt a push notification
I have also done other variations of the above where i have included "topicId:_broadcast" to no avail.
Is there something in the formatting that i have wrong? or missing information i should have included.
You got the format a bit wrong. It should be :
{
"registration_ids":["xxx", "yyy"],
"data": {
"message": "test",
"duration": "5"
}
}
Related
I'm trying to get push notifications running with React Native on iOS and Android.
To do so I am using firebase, as that seemed to be very convenient.
On Android I managed to show notifications when the app is in the foreground and at least show a log when the app is in the background, meaning I can process them.
On iOS I have not managed to do any of those, not from our custom backend in aws (via SNS), nor from firebase console with fcm token. What interestingly worked, was to show a badge on the ios app icon when sending broadcast messages to all users. So something seems to be received on the phone.
Now looking into this a little deeper I found that iOS needs notifications in the following format:
{
"Simulator Target Bundle": "com.compass.SomeExampleApp",
"aps": {
"badge": 0,
"alert": {
"title": "Push Notification Test",
"subtitle": "Hey! 👋",
"body": "Is this working?",
},
"sound":"default"
}
}
At least this is how you can test them on the sim.
1. Does it mean that I have to send the notifications in that same format? Or can it be something like:
{
"data":{},
"apns": {
"Simulator Target Bundle": "com.company.Example",
"aps": {
"alert": {
"body": "Wellcome to MyApp!",
"title": "MyApp"
}
}
}}
2. How can I send a format that iOS AND Android can read, show on screen and process in background if necessary?
Since we are sending only data messages I think this might be part of the issue, if I look at our backend.
Still when sending from firebase I am not able to show anything on screen on ios Device. Any hint?
I found a solution that actually works on both platforms although it is a bit weird since it seems to be outdated. Code needs to look like this to send to both iOS and Android:
{ "GCM": "{ \"notification\" : {\"content_available\" : true }, \"data\": { \"body\": \"Sample message for iOS endpoints\", \"title\":\"Hello world\"} }" }
As seen here APNS attributes seem to at least partly work if added within the GCM message like content_available in this case or badge.
I've read all the related SO questions, most of which were asked in answered in 2017 or early 2018, before Google simplified the way Instant Apps could be created. In my case, I created an "instant enabled app bundle" (described here) that works both as an app and as an instant app.
The app bundle includes a library I wrote that is configured to receive Firebase messages (described here) from the AWS Simple Notification Service (SNS). The problem is that messages are received when the app is run, but not received when the instant app is run.
The good news is that when I look at the AWS CloudWatch console, I can see every failed attempt. Here is the relevant part of the message:
"providerResponse": "{\"results\":[{\"error\":\"InvalidParameters: DisplayNotificationRequired\"}],\"multicast_id\":\"8198293557962051\",\"success\":0,\"failure\":1,\"canonical_ids\":0}"
The message content is:
{
"to" : "fi_Pclw7RrWtPm0xMVSgbC:APA91bGJFzM6RQVisO0N_JOAb8rUOKBVPZ0I5jh9Vf-4f-xXtbQY_Ik7q3wLGeCbR5bh_lFWDy0PX-F2mIlamMlCTIuEqEOlk0KcFO9a5fYk6B_omGqevjY6KNiByI5j_vKQaF17Rif8",
"data" : {
"body" : "Content message",
"title": "the Title",
"key_1" : "Value for key_1",
"key_2" : "Value for key_2"
}
}
I've searched for the DisplayNotificationRequired error but can't find anything. Anyone know what this means and how to fix? Thanks!
Since I wrote the above, I tried adding a notification object as well:
{
"to" : "fi_Pclw7RrWtPm0xMVSgbC:APA91bGJFzM6RQVisO0N_JOAb8rUOKBVPZ0I5jh9Vf-4f-xXtbQY_Ik7q3wLGeCbR5bh_lFWDy0PX-F2mIlamMlCTIuEqEOlk0KcFO9a5fYk6B_omGqevjY6KNiByI5j_vKQaF17Rif8",
"notification" : {
"body" : "Content message",
"title": "the Title"
},
"data" : {
"body" : "Content message",
"title": "the Title",
"key_1" : "Value for key_1",
"key_2" : "Value for key_2"
}
}
Now I'm getting an error with MissingDataUri instead of a DisplayNotificationRequired error. When I use Postman to send this message directly to the device token, I also get a MissingDataUri error, so I'm thinking this is not a AWS SNS or a Firebase Cloud Messaging issue, but just an instant app issue.
Finally, I understand that there was an "instant app notifications beta" way back in 2018 that appears to be still running: https://g.co/instantapps/notifications
Is it still not possible to send a push notification to an instant app, specifically with a 'data' payload? (I went ahead an submitted the form...just in case.)
Thanks all!
The only way you can do it is with a notification attached to a foreground service.
Remote notifications are currently not possible with instant apps.
Can I ask why you want to do it? An instant app should deliver an instant experience and you should assume that the user will either install the full version, or abandon it after closing the app. So remote notifications does not make much sense, unless it is attached to the "experience" the user is expecting.
If a notification flow is necessary for the experience, you should use a foreground service. A good example could be if you buy a drop-in service that has a queue (hairdresser for example) and you want to notify the user during the waiting time.
In this case you could create a foreground service with an attached notification. The service polls your backend in the background to get a time estimate and queue position, and then update the notification accordingly. When the user is finished with his haircut, you can close the foreground service and thus allowing the app to be removed from the device automatically.
Read more about services: https://developer.android.com/guide/components/services
You will need: https://developer.android.com/reference/android/Manifest.permission#INSTANT_APP_FOREGROUND_SERVICE
I have an app with Android and iOS users, subscribed to Firebase Clould Messaging topics. Some users have access to send a message to these topics. I make an http request to send the message. The body looks like this:
{
"to": "/topics/debug"
"notification" : {
"body" : "Hi there",
"title" : "Wow!",
"sound": "default"
},
"priority": "high"
"data": {
"title": "Hi there",
"body": "Wow",
}
}
For android, in order to send data message, I need to use the "data" key, so that onMessageReceived is called.
However, ios needs the "notification" key, so that even if the app is killed the message will display. But, whenever I add the "notification" key, the android devices don't call onMessageReceived, and it isn't treated as a data message.
How can I solve this issue, to make one request which is work for both devices. If I do two requests (one with "notification" for ios, and one with "data" for android, the android devices get two notifications (one from onMessageReceived, and one from the system. Can I stop the android devices from showing the message if its sent with just the "notification" key?
I hope I explained the issue well, since this is how I understand the problem I have.
Thanks
I'm not sure this counts as an answer, but I realised an easy workaround, that I prescribed different topics to android and ios users, and set different code appropriate for each one, instead of having one topic for all users.
This question already has answers here:
Firebase notification records/log API
(2 answers)
Closed 4 years ago.
I am testing the Firebase JSON to check the delivery receipts of the notification sent to the news app. I can successfully send the message to the Android app without any issues and I receive the message on my Android app. However, I want to know how and where can I check if the notification was successfully delivered to the Android app?
How do I use the message_id and/or multicast_id that is given back to get the delivery status of the notification? I can't find working code examples of checking for delivery status with Firebase. Does anyone have working JSON code to query the delivery status of a Firebase message via the message_id and/or multicast_id or another way? The Firebase documentation does not give examples on how to do this (or maybe I missed the example).
Please see the Firebase JSON below used to send the notification to the Firebase news app. Anyone's help is highly appreciated.
In the header I set authorization key=firebase_server_key
and content type is set to application/json
{
"to" : "token received from firebase",
"notification" : {
"body" : "test",
"title" : "Alert",
"icon" : "myicon",
"delivery_receipt_requested": true
}
}
Output from postman:
{"multicast_id":7845213569874521,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:4853214789631%31bd1c9631bd1c96"}]}
Update:
The Diagnostics Tool has been removed since Nov. 30, 2017:
You can no longer access FCM diagnostics data in the Play Console.
Confirming what #user7410521 said in the comments section. There is currently no available API to make use of the message_ids/multicast_ids to retrieve the details of the delivery status of the message sent, other than using the FCM Diagnostics Page. Do also keep in mind that the Diagnostics page is only usable when the app is already published (for Alpha testing or later).
I noticed that you included the delivery_receipt_requested parameter in your payload. Receiving the a message confirmation should be enough to determine that the device received the message.
Though there is no API so far also I could find out. I have tried a workarond. From the server side PHP I am sending an FCM message. Let me present how I have handled this in PHP.
$fcm_return = fcm_message_send($message);
$fcm_return_JSON = json_decode($fcm_return, true);
echo $$fcm_return_JSON['success'];
As I am sending a message to one device, I am comparing return with 1. Based on this you could further implement your logic.
I have written a program to send a simple text message as push to both iOS and Android devices. However, I have been told that I should not bother the users to write their own JSON. So all I ask from the user is to write the body of the message.
In iOS this will be assigned to the alert attribute in their JSON. But I see on Android that you can have different variables. So I am looking for the attribute that will always work as the message text. This is my Android message JSON:
{
'title':'no title',
'body':'This is the text message!'
}
But I am wondering if body is a standard tag I can use with any app? Or will it become unavailable if the users connects my program to another app?
This format should work for both iOS and Android:
{
"alert": "My_Alert_Text",
"title": "My_Alert_Title",
"myKey1": "Custom_Value_1",
"myKey2": "Custom_Value_2",
....
"myKeyN": "Custom_Value_N"
}