I am trying to send push notification to ios device via firebase and also I need to send category object with the aps payload so that I can create notification with action buttons. I am using the below payload specified in firebase documentation, but I am unable to receive the category object in the aps payload object in the front end. Any help would be appreciable. Thanks in advance.
{
"message": {
"token": "f8vYHFfogAA:APA91bG7cZlo7Iimv1UtD0atqTlBRKYsGTU2pdWQmfELpdG61E4_TstS8MNHvHgNJW_dECi8YxD0REiDjxbkBVK4Ey9MNJ4MTxBVJpa48sirKb2a93QyfrpRwDMB9_j8UaNexP5rQ7Ci",
"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": "100"
},
"payload": {
"aps": {
"category": "NEW_MESSAGE_CATEGORY"
}
}
},
"webpush": {
"headers": {
"TTL": "86400"
}
}
}
}
Related
I've implemented Silent push notification, but it has a sound like the normal ones. Help me to correctly implement this.
Here's the payload that we're sending from Backend to FCM:
{
"notification": {
"messageId": "24d0f68a24d"
},
"content_available": true,
"data": {
"requestId": "231DDD",
"messageId": "f68a24d",
"event": "REMOVE_NOTIFICATION",
"message": ""
},
"apns": {
"headers": {
"apns-push-type": "background",
"apns-priority": 5
}
},
"to": "FCM_Token",
"priority": "high"
}
To make this silent, you have to remove following part.
"notification": {
"messageId": "24d0f68a24d"
},
I want my Cloud Function to send a push notification to a specific topic, which works just fine. However, when I'm adding the "badge" field, the following error occurs:
Unknown name "badge" at 'message.notification': Cannot find field.
What am I supposed to do if I want to specify a badge number for iOS devices? The code I have looks like follows:
exports.onAddLog = functions.database.ref("/NodesLog/{id}").onCreate((change, context) => {
const payload = {
"topic": "Channel123",
"notification": {
"title": "Test-Title",
"body": "Test-Body",
"badge": "1"
},
"data": {
"test": "test",
"notId": "123"
}
}
const promise : Promise<any> = admin.messaging().send(payload)
.catch(error => console.error("Error on send: " + error))
.then(sendSuccess => console.log("Notification send "))
.catch(() => console.error("What happened?"))
return promise;
})
The problem is that badge is iOS field and it should be in another place as Ali said it is in "aps" object. But what he didn't say is where aps should be.
for example this should be your message
{
"message":{
"topic": "Channel123",
"notification": {
"title": "Test-Title",
"body": "Test-Body",
"badge": "1"
},
"data": {
"test": "test",
"notId": "123"
},
"apns": {
"payload": {
"aps": {
"badge": 5
}
}
}
}
}
I took the example from here
try to add aps node containing badge property with your payload
const payload = {
...
"aps":{
"alert":"test alert",
"badge":5,
"sound":"default"
}
}
The following payload worked for me on both Android and iOS:
payload = {
notification: {
"title": "Message Title",
"body": "Message Body",
"click_action": ".MainActivity",
"badge": "1",
},
data: {
"my_message_type": "foo",
"my_id": "bar",
},
};
const payload = {
token: "FCMToken",
notification: {
title: "title",
body: "body",
},
apns: {
payload: {
aps: {
badge: 5,
sound: "default",
},
},
},
};
I am trying to send test push from Urban Airship portal. I have got channel ID of device, created JSON payload. However when I am trying to send, it always show error, Sorry, this doesn't look like valid JSON. Below is my Payload data, please help me in this.
{
"audience": {
"ios_channel": "938a3a93-1a5f-466c-923b-827ef4b0a75b"
},
"notification": {
"aps": {
"alert": {
"body": "Sample",
"title": "Sample"
}
}
"ios": {
"badge": 3
}
},
"device_types": [
"ios"
]
}
This valid , you forget a comma , you may use https://jsonlint.com for such things
{
"audience": {
"ios_channel": "938a3a93-1a5f-466c-923b-827ef4b0a75b"
},
"notification": {
"aps": {
"alert": {
"body": "Sample",
"title": "Sample"
}
},
"ios": {
"badge": 3
}
},
"device_types": [
"ios"
]
}
I am construing below payload. If i send required data object inside aps object then i am able to recieve the data even when application is quit and user taps on tray,
{
"aps": {
"content-available":1,
"alert": {
"title": "Game Request",
"body": "Bob wants to play poker"
},
"sound": "default",
"data": {
"alertType": "ALERT",
"eventTime": "121346666545454",
"deviceId": "657585685858",
"user":"Arun"
}
},
}
As per the standard format we have to place data outside the aps object which i saw in APNS documentation like.
{
"aps": {
"content-available":1,
"alert": {
"title": "Game Request",
"body": "Bob wants to play poker"
},
"sound": "default"
},
"data": {
"alertType": "ALERT",
"eventTime": "121346666545454",
"deviceId": "657585685858",
"user":"Arun"
}
}
Can anyone please suggest me which is IOS APNS standard format. since i am new to IOS.
As per below URL https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CreatingtheNotificationPayload.html#//apple_ref/doc/uid/TP40008194-CH10-SW1.
we have to send the app-specific data outside the aps. if we send we are not getting in app when user comes from notification tray click.
Thanks in advance
I am using FCM for my project. It's have rich push notification for a type. I tried to modified most of possible ways to get push from FCM. I got obly ordinary push from FCM, not with image.
I am also check with APNS same coding using push try. I got what expected design for push notification.
Here my APNS payload
{
"aps": {
"alert": "Enter your message",
"badge": 1,
"sound": "default",
"content-available": 1,
"mutable-content": 1
},
"mediaUrl": "https://upload.wikimedia.org/wikipedia/commons/thumb/2/2a/FloorGoban.JPG/1024px-FloorGoban.JPG"
}
Here FCM payload
{
"to": "dWB537Nz1GA:APA91bHIjJ5....",
"data":
{
"message": "Offer!",
"mediaUrl": "https://upload.wikimedia.org/wikipedia/commons/thumb/2/2a/FloorGoban.JPG/1024px-FloorGoban.JPG"
},
"notification":
{
"body": "Enter your message",
"sound": "default",
"content-available": 1,
"mutable-content": 1
}
}
Also I am need category more details about payload in FCM
Am I missing any setting in fire-base console or is that from payload.
The mutable-content and content-available in your FCM payload is incorrect. It should be formatted as mutable_content and content_available. Both are boolean and must also be outside the notification parameter. Like so:
{
"to": "dWB537Nz1GA:APA91bHIjJ5....",
"content_available": true,
"mutable_content": true,
"data":
{
"message": "Offer!",
"mediaUrl": "https://upload.wikimedia.org/wikipedia/commons/thumb/2/2a/FloorGoban.JPG/1024px-FloorGoban.JPG"
},
"notification":
{
"body": "Enter your message",
"sound": "default"
}
}
For the counterpart of category in FCM, you should use click_action:
The action associated with a user click on the notification.
Corresponds to category in the APNs payload.
This worked for me. The accepted answer seems to have some unnecessary information.
{
"to" : "devicekey OR /topics/sometopic",
"mutable_content": true,
"data": {
"mymediavideo": "https://myserver.com/myvideo.mp4"
},
"notification": {
"title": "my title",
"subtitle": "my subtitle",
"body": "some body"
}
}