I'm using Firebase to send message across iOS & Android devices. I follow the document of google but it's still not working.
https://firebase.google.com/docs/cloud-messaging/concept-options
In the document, they gave an example
{
"message":{
"token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"notification":{
"title":"Match update",
"body":"Arsenal goal in added time, score is now 3-0"
},
"android":{
"ttl":"86400s",
"notification"{
"click_action":"OPEN_ACTIVITY_1"
}
},
"apns": {
"headers": {
"apns-priority": "5",
},
"payload": {
"aps": {
"category": "NEW_MESSAGE_CATEGORY"
}
}
},
"webpush":{
"headers":{
"TTL":"86400"
}
}
}
}
and I replaced some placeholders of this example with my Firebase configurations then I ran Postman and it returned 400 bad Request
{
"message":{
"token":"dRnhMNngY02mofqQ-5no8K:APA91bEcaaZ3QBWTdZfN3hU1tJzy6_ChW4FMArXbbWvT-8wq11TDN2jLy7uaT-Wzjq_xAzPqZfVje5_n54pVLnCfUUPTp_EuS3CykGnysHO0BeJn0TEgP-czc_y2kdyVMW-39mlSh8-t",
"notification":{
"title":"Match update",
"body":"Arsenal goal in added time, score is now 3-0"
},
"android":{
"ttl":"86400s",
"notification": {
"click_action":"OPEN_ACTIVITY_1"
}
},
"apns": {
"headers": {
"apns-priority": "5"
},
"payload": {
"aps": {
"category": "NEW_MESSAGE_CATEGORY"
}
}
},
"webpush":{
"headers":{
"TTL":"86400"
}
}
}
}
But when I changed it. Set to & notification to the first level of json. My iOS device displayed a notification.
{
"to": "dRnhMNngY02mofqQ-5no8K:APA91bEcaaZ3QBWTdZfN3hU1tJzy6_ChW4FMArXbbWvT-8wq11TDN2jLy7uaT-Wzjq_xAzPqZfVje5_n54pVLnCfUUPTp_EuS3CykGnysHO0BeJn0TEgP-czc_y2kdyVMW-39mlSh8-t",
"notification": {
"title": "Match update",
"body": "Arsenal goal in added time, score is now 3-0"
}"message": {
"token": "dRnhMNngY02mofqQ-5no8K:APA91bEcaaZ3QBWTdZfN3hU1tJzy6_ChW4FMArXbbWvT-8wq11TDN2jLy7uaT-Wzjq_xAzPqZfVje5_n54pVLnCfUUPTp_EuS3CykGnysHO0BeJn0TEgP-czc_y2kdyVMW-39mlSh8-t",
"notification": {
"title": "Match update",
"body": "Arsenal goal in added time, score is now 3-0"
},
"android": {
"ttl": "86400s",
"notification": {
"click_action": "OPEN_ACTIVITY_1"
}
},
"apns": {
"headers": {
"apns-priority": "5"
},
"payload": {
"aps": {
"category": "NEW_MESSAGE_CATEGORY"
}
}
},
"webpush": {
"headers": {
"TTL": "86400"
}
}
}
}
I don't know why the example of Firebase from Google is not working? Moreover, I tried to send to my Android device, it said "InvalidRegistration" message but when I tested sending message in https://console.firebase.google.com -> Cloud Messaging -> Compose notification. I pasted the same token that I used to test Android and it worked...
Really confused?!
I found several articles and test but it did work for me. I just want to have a structure of json file to work for both iOS and Android (also need to send both type of message as: notification & data)
Can anyone help me to fix this issue?
Thank you a lot,
Just want to up this question and not to be missed
Related
I'm sending push notifications to my app via the firebase admin API. I use "DeviceGroups" to register my user's devices. Then I send notifications to the specific device group. The notifications are received well, bu in the firebase console, I can't see any label I added in the analytics label tag.
Here is the format of my message:
{
"to": "...",
"notification": {
"title": "LabelUno",
"body": "Messager",
"image": ""
},
"data": {
"apns_collapse_id": "id"
},
"apns": {
"headers": null,
"fcm_options": null,
"payload": {
"aps": {
"badge": null,
"category": null,
"thread-id": null,
"alert": null,
"sound": null,
"content-available": 1,
"mutable-content": 1
}
}
},
"fcmOptions": {
"analytics_label": "LabelUno"
}
}
I found this while researching the cause of this issue, but we are actively looking for a work arround. Please can anyone help ?
I have integrated pubnub API in one of my project. I am trying to get bundle of data that i have sent in payload. I have added FCM for push notification. I am getting push notification in all cases but not getting bundle data when app is killed or in background. Already getting payload object when app is in foreground but not getting any data when app is in background or killed.
Payload 1 :
{
"pn_gcm": {
"notification": {
"title": "Barack Obama",
"body": "12",
"channelName": "Hell 4_656"
}
},
"firstName": "Barack",
"lastName": "Obama",
"displayName": "Barack Obama",
"profileImageUrl": "abcURL",
"userId": "173",
"type": "sender",
"time": "1615958943297",
"message": "12"
}
PayLoad 2 :
{
pn_gcm={
notification={
title=BarackObama,
body=Hello,
image=Hell4_656
}
},
firstName=Barack,
lastName=Obama,
displayName=BarackObama,
time=1615958740553,
type=sender,
message=Hello,
profileImageUrl=abcURL,
userId=173
}
I am getting notification object when app is in foreground but not getting any of them when app is in background or killed.(Getting some FCM default object)
I am trying to get notification object in bundle when launch app from Notification tray
Answer
Made JSON payload like this :
{
"pn_gcm": {
"notification": {
"title": "Barack Obama",
"body": "18"
},
"body": {
"channelName": "Hell 5_657",
"firstName": "Barack",
"lastName": "Obama",
"displayName": "Barack Obama",
"profileImageUrl":
"http://3.137.127.137/quiqle/uploads/profile/1615523786_4866.jpg",
"userId": "173",
"type": "sender",
"time": "1615965488916",
"message": "18"
}
}
}
You need to add data with information which you want to receive with push into pn_gcm.
Information outside of pn_(gcm|apns) (including tjpse) will be delivered as regular messages
Message can be as follows:
using notification:
{
"pn_gcm":{
"notification":{
"title":"Chat invitation",
"body":"John invited you to chat",
"sound":"default"
}
}
}
Or using data:
{
"pn_gcm" : {
"data" : {
"room" : "Portugal vs Denmark",
"body" : "great match!"
}
}
}
or both:
{
"pn_gcm" : {
"notification": {
"title":"Portugal vs Denmark",
"body":"great match!"
},
"data" : {
"room" : "Portugal vs Denmark",
"body" : "great match!"
}
}
}
For an explanation on the different between data and notification, please read the official FCM docs, About FCM messages.
See also:
Why are my FCM push notifications not working?
I am trying to send image in push notification from firebase console but it doesn't work, so i tried to send from the postman but it doesn't work either. I tried other parameters like icon, image, media_url, mediaImgUrl..etc from Internet in the body.
Help me out here so that i can send image in notification.
{
"to": "tokennnnnnnnnnnn............",
"content_available": true,
"mutable_content": true,
"data":
{
"message": "Hey!",
"icon": ".....farm.png"
},
"notification":
{
"body": "Topic",
"sound": "default",
"icon": ".....farm.png"
}
}
Try sending image with this payload :
{
"message":{
"token" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"android": {
"notification": {
"body" : "This is an FCM notification that displays an image.!",
"title" : "FCM Notification",
"image": "url-to-image"
}
}
}
I have a Cordova app, using the push plugin.
On the server I am sending the GCM messages with node-gcm.
I receive notifications just fine, for iOS and Android, and they open the app when clicked, however on Android the 'notification' event does not fire.
push.on('notification', function(data) {
console.log(data);
alert('got PUSH!');
});
If the app is running in the foreground then I get the 'got PUSH!' alert, but when the app is in the background and I click the push notification when it arrives, it opens the app but does not alert 'got PUSH!'.
How can I get the 'notification' event to fire after the app opens?
Here is the gcm Message I am sending to the device:
{
"params": {
"notification": {
"title": "SO post demo",
"body": "THIS IS A TEST!",
"icon": "ic_launcher",
"sound": true
}
}
}
I believe that I need to have something in the notification payload to solve this, but nothing I have tried gets that event to fire when the app opens from the background.
Here are a couple of things that I have tried:
Using "content-available" (as suggested here), using message.addData:
{
"params": {
"notification": {
"title": "SO post demo",
"body": "THIS IS A TEST!",
"icon": "ic_launcher",
"sound": true
},
"data": {
"info": "super secret info",
"content-available": "1"
}
}
}
Same again, but putting my params in the json I use to make the Message:
{
"params": {
"notification": {
"title": "SO post demo",
"body": "THIS IS A TEST!",
"icon": "ic_launcher",
"sound": true,
"info": "super secret info",
"content-available": "1"
}
}
}
In methodically creating this question I found the answer.
I needed my payload to look like this:
{
"params": {
"data": {
"title": "SO post demo",
"body": "THIS IS A TEST!",
"icon": "ic_launcher",
"sound": true
}
}
}
This messes up the notification icon that displays (it is a zoomed in version) but, at this stage, I can live with that.
I am using Firebase Database for my mobile and web application. I wanted to get advise for how to structure the JSON Tree. I have the following use case in mind:
Mobile app user logs in and gets all nearby restaurants in a list. User sets order on one restaurant. The restaurant owner uses web or mobile application to see incoming orders and accepts them. After accepting the order, the mobile app user gets response that his order has been accepted. Now my idea for the structure was the following:
SO we have one node at top level for each restaurant and each restaurant node contains a requests node which saves all the requests for this restaurants.
Is that structure ok or could this be structured better?
Consider a data structure like this, you don't want to retrieve all the request when you get a restaurant and this way, you can get all the requests for a restaurant and all the requests from a particular user.
{
"requests": {
"req1": {
"status": 0,
"time": 1473593287,
"user": { "u2": true }
},
"req2": {
"status": 0,
"time": 1473593227,
"user": { "u1": true }
},
"req3": {
"status": 0,
"time": 1473594287,
"user": { "u1": true }
},
"req4": {
"status": 0,
"time": 1473594227,
"user": { "u2": true }
},
},
"restaurant-requests": {
"resA": {
"req1": true,
"req2": true
},
"resB": {
"req3": true,
"req4": true
}
},
"restaurants": {
"resA": {
"name": "Example Restaurant A",
"address": "1 Example Street"
},
"resB": {
"name": "Example Restaurant B",
"address": "2 Example Street"
}
},
"user-requests": {
"u1": {
"req2": true,
"req3": true
},
"u2": {
"req1": true,
"req4": true
}
},
"users": {
"u1": {
"address": "123 Example Street"
},
"u2": {
"address": "124 Example Street"
},
},
}
That's what I would do..
good luck!