Firebase FCM silent push notifications for iOS
I have a problem with silent notifications on iOS.
When my application is in background, I don't receive silent notification sent by FCM. But if I try to send directly to APNS, the notification is successfully received.
This is the JSON sent to FCM:
{
"to" : "<token>",
"priority": "high",
"content_available": true,
"data" : {
"<key>" : "<string>",
"<key2>" : "<string>"
}
}
This is the JSON sent directly to APNS:
{
"aps": {
"content-available": 1
},
"<key>": "<string>",
"<key>": "<string>"
}
I have already tried to remove the "priority" key because I saw someone saying that I shouldn't set the priority if the "content_available" is already set. It didn't work.
- I have "Push Notifications" enabled in XCode > Capabilities.
- I have "Remote notifications" checked in Background Modes in XCode > Capabilities.
- The FCM notifications are working fine when app is in foreground and sometimes when the app is in background.
ios firebase notifications apple-push-notifications firebase-cloud-messaging
add a comment |
I have a problem with silent notifications on iOS.
When my application is in background, I don't receive silent notification sent by FCM. But if I try to send directly to APNS, the notification is successfully received.
This is the JSON sent to FCM:
{
"to" : "<token>",
"priority": "high",
"content_available": true,
"data" : {
"<key>" : "<string>",
"<key2>" : "<string>"
}
}
This is the JSON sent directly to APNS:
{
"aps": {
"content-available": 1
},
"<key>": "<string>",
"<key>": "<string>"
}
I have already tried to remove the "priority" key because I saw someone saying that I shouldn't set the priority if the "content_available" is already set. It didn't work.
- I have "Push Notifications" enabled in XCode > Capabilities.
- I have "Remote notifications" checked in Background Modes in XCode > Capabilities.
- The FCM notifications are working fine when app is in foreground and sometimes when the app is in background.
ios firebase notifications apple-push-notifications firebase-cloud-messaging
add a comment |
I have a problem with silent notifications on iOS.
When my application is in background, I don't receive silent notification sent by FCM. But if I try to send directly to APNS, the notification is successfully received.
This is the JSON sent to FCM:
{
"to" : "<token>",
"priority": "high",
"content_available": true,
"data" : {
"<key>" : "<string>",
"<key2>" : "<string>"
}
}
This is the JSON sent directly to APNS:
{
"aps": {
"content-available": 1
},
"<key>": "<string>",
"<key>": "<string>"
}
I have already tried to remove the "priority" key because I saw someone saying that I shouldn't set the priority if the "content_available" is already set. It didn't work.
- I have "Push Notifications" enabled in XCode > Capabilities.
- I have "Remote notifications" checked in Background Modes in XCode > Capabilities.
- The FCM notifications are working fine when app is in foreground and sometimes when the app is in background.
ios firebase notifications apple-push-notifications firebase-cloud-messaging
I have a problem with silent notifications on iOS.
When my application is in background, I don't receive silent notification sent by FCM. But if I try to send directly to APNS, the notification is successfully received.
This is the JSON sent to FCM:
{
"to" : "<token>",
"priority": "high",
"content_available": true,
"data" : {
"<key>" : "<string>",
"<key2>" : "<string>"
}
}
This is the JSON sent directly to APNS:
{
"aps": {
"content-available": 1
},
"<key>": "<string>",
"<key>": "<string>"
}
I have already tried to remove the "priority" key because I saw someone saying that I shouldn't set the priority if the "content_available" is already set. It didn't work.
- I have "Push Notifications" enabled in XCode > Capabilities.
- I have "Remote notifications" checked in Background Modes in XCode > Capabilities.
- The FCM notifications are working fine when app is in foreground and sometimes when the app is in background.
ios firebase notifications apple-push-notifications firebase-cloud-messaging
ios firebase notifications apple-push-notifications firebase-cloud-messaging
edited Nov 25 '16 at 15:33
Frank van Puffelen
238k29382408
238k29382408
asked Nov 25 '16 at 14:42
vladiulianbogdanvladiulianbogdan
1,4631513
1,4631513
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
Remove "notification" key value pair and add "content_available": true
It will look like this
{
"to" : "...",
"priority": "high",
"content_available": true,
"data" : {
....
}
}
This should make it a silent APNS and you need to handle with corresponding APNS delegate method.
You will need to handle this through delegates
Refer this firebase documentation for details: https://firebase.google.com/docs/cloud-messaging/concept-options
add a comment |
I found an workaround. I put an empty value for "sound" in "notification" field and the silent notifications are delivered even when the application is in background.
{
"to" : "...",
"priority": "high",
"notification": {
"sound": ""
},
"data" : {
....
}
}
My hunch is that Apple does not allow silent notifications with a 'high' priority and somehow "notification": {"sound": ""} tricks the APNS that this notification is not a silent one.
3
Right after you set the notification object, it becomes a normal push notification. It's not a silent push notification at al.
– Dinesh Raja
Dec 23 '16 at 10:26
what to do to send the silent notification through FCM message console ?
– Moxarth
Dec 11 '17 at 13:02
add a comment |
I was working on Firebase silent push notification using nodejs. When I tried below code its was working fine. When I was adding "priority": "high" and "content_available": true it was giving below error.
Worked below code
const admin = require('firebase-admin');
const serviceAccount ="...."; //service account path
admin.initializeApp({
credential: admin.credential.cert(serviceAccount)
});
let fcmToken = "...."; // Your token
let message ={
"token": fcmToken,
"data": {
"updateApi": "activity"
}
}
admin.messaging().send(message)
.then((response) =>{
console.log('Successfully sent notification:', response);
})
.catch((error) =>{
console.log('Error while sending notification:', error);
});
Error when I added the priority and content_available in message object
{ code: 'messaging/invalid-argument',
message: 'Invalid JSON payload received. Unknown name "priority" at 'message': Cannot find field.nInvalid JSON payload received. Unknown name "content_available" at 'message': Cannot find field.' },
codePrefix: 'messaging' }
HAve you solved this?
– Shubham1164
Feb 1 at 18:10
1
Yes, Just don't pass priority and content_available in above message object
– Priy Ranjan
Feb 5 at 10:03
Then how to control the values of these. Where I can change priority and content_available values?
– Shubham1164
Feb 5 at 10:09
add a comment |
Please follow the documentation for server side and make setup for json as explained over the document. I have faced similiar problem earlier and solved the issue going this doc.
{
"to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"priority" : "high",
"notification" : {
"body" : "This week's edition is now available.",
"title" : "NewsMagazine.com",
"icon" : "new"
},
"data" : {
"volume" : "3.21.15",
"contents" : "http://www.news-magazine.com/world-week/21659772"
}
}
you were missing notification key. which is used by apns to get notification on background.
5
But I don't want the user to receive a notification in the Notification Center. I just want a silent notification that will execute some code in the "didReceiveRemoteNotification". That's what "silent notification" means.
– vladiulianbogdan
Nov 25 '16 at 15:18
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f40807397%2ffirebase-fcm-silent-push-notifications-for-ios%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
Remove "notification" key value pair and add "content_available": true
It will look like this
{
"to" : "...",
"priority": "high",
"content_available": true,
"data" : {
....
}
}
This should make it a silent APNS and you need to handle with corresponding APNS delegate method.
You will need to handle this through delegates
Refer this firebase documentation for details: https://firebase.google.com/docs/cloud-messaging/concept-options
add a comment |
Remove "notification" key value pair and add "content_available": true
It will look like this
{
"to" : "...",
"priority": "high",
"content_available": true,
"data" : {
....
}
}
This should make it a silent APNS and you need to handle with corresponding APNS delegate method.
You will need to handle this through delegates
Refer this firebase documentation for details: https://firebase.google.com/docs/cloud-messaging/concept-options
add a comment |
Remove "notification" key value pair and add "content_available": true
It will look like this
{
"to" : "...",
"priority": "high",
"content_available": true,
"data" : {
....
}
}
This should make it a silent APNS and you need to handle with corresponding APNS delegate method.
You will need to handle this through delegates
Refer this firebase documentation for details: https://firebase.google.com/docs/cloud-messaging/concept-options
Remove "notification" key value pair and add "content_available": true
It will look like this
{
"to" : "...",
"priority": "high",
"content_available": true,
"data" : {
....
}
}
This should make it a silent APNS and you need to handle with corresponding APNS delegate method.
You will need to handle this through delegates
Refer this firebase documentation for details: https://firebase.google.com/docs/cloud-messaging/concept-options
answered Mar 20 '17 at 11:16
Alap AneraoAlap Anerao
1,4801223
1,4801223
add a comment |
add a comment |
I found an workaround. I put an empty value for "sound" in "notification" field and the silent notifications are delivered even when the application is in background.
{
"to" : "...",
"priority": "high",
"notification": {
"sound": ""
},
"data" : {
....
}
}
My hunch is that Apple does not allow silent notifications with a 'high' priority and somehow "notification": {"sound": ""} tricks the APNS that this notification is not a silent one.
3
Right after you set the notification object, it becomes a normal push notification. It's not a silent push notification at al.
– Dinesh Raja
Dec 23 '16 at 10:26
what to do to send the silent notification through FCM message console ?
– Moxarth
Dec 11 '17 at 13:02
add a comment |
I found an workaround. I put an empty value for "sound" in "notification" field and the silent notifications are delivered even when the application is in background.
{
"to" : "...",
"priority": "high",
"notification": {
"sound": ""
},
"data" : {
....
}
}
My hunch is that Apple does not allow silent notifications with a 'high' priority and somehow "notification": {"sound": ""} tricks the APNS that this notification is not a silent one.
3
Right after you set the notification object, it becomes a normal push notification. It's not a silent push notification at al.
– Dinesh Raja
Dec 23 '16 at 10:26
what to do to send the silent notification through FCM message console ?
– Moxarth
Dec 11 '17 at 13:02
add a comment |
I found an workaround. I put an empty value for "sound" in "notification" field and the silent notifications are delivered even when the application is in background.
{
"to" : "...",
"priority": "high",
"notification": {
"sound": ""
},
"data" : {
....
}
}
My hunch is that Apple does not allow silent notifications with a 'high' priority and somehow "notification": {"sound": ""} tricks the APNS that this notification is not a silent one.
I found an workaround. I put an empty value for "sound" in "notification" field and the silent notifications are delivered even when the application is in background.
{
"to" : "...",
"priority": "high",
"notification": {
"sound": ""
},
"data" : {
....
}
}
My hunch is that Apple does not allow silent notifications with a 'high' priority and somehow "notification": {"sound": ""} tricks the APNS that this notification is not a silent one.
answered Dec 15 '16 at 10:42
vladiulianbogdanvladiulianbogdan
1,4631513
1,4631513
3
Right after you set the notification object, it becomes a normal push notification. It's not a silent push notification at al.
– Dinesh Raja
Dec 23 '16 at 10:26
what to do to send the silent notification through FCM message console ?
– Moxarth
Dec 11 '17 at 13:02
add a comment |
3
Right after you set the notification object, it becomes a normal push notification. It's not a silent push notification at al.
– Dinesh Raja
Dec 23 '16 at 10:26
what to do to send the silent notification through FCM message console ?
– Moxarth
Dec 11 '17 at 13:02
3
3
Right after you set the notification object, it becomes a normal push notification. It's not a silent push notification at al.
– Dinesh Raja
Dec 23 '16 at 10:26
Right after you set the notification object, it becomes a normal push notification. It's not a silent push notification at al.
– Dinesh Raja
Dec 23 '16 at 10:26
what to do to send the silent notification through FCM message console ?
– Moxarth
Dec 11 '17 at 13:02
what to do to send the silent notification through FCM message console ?
– Moxarth
Dec 11 '17 at 13:02
add a comment |
I was working on Firebase silent push notification using nodejs. When I tried below code its was working fine. When I was adding "priority": "high" and "content_available": true it was giving below error.
Worked below code
const admin = require('firebase-admin');
const serviceAccount ="...."; //service account path
admin.initializeApp({
credential: admin.credential.cert(serviceAccount)
});
let fcmToken = "...."; // Your token
let message ={
"token": fcmToken,
"data": {
"updateApi": "activity"
}
}
admin.messaging().send(message)
.then((response) =>{
console.log('Successfully sent notification:', response);
})
.catch((error) =>{
console.log('Error while sending notification:', error);
});
Error when I added the priority and content_available in message object
{ code: 'messaging/invalid-argument',
message: 'Invalid JSON payload received. Unknown name "priority" at 'message': Cannot find field.nInvalid JSON payload received. Unknown name "content_available" at 'message': Cannot find field.' },
codePrefix: 'messaging' }
HAve you solved this?
– Shubham1164
Feb 1 at 18:10
1
Yes, Just don't pass priority and content_available in above message object
– Priy Ranjan
Feb 5 at 10:03
Then how to control the values of these. Where I can change priority and content_available values?
– Shubham1164
Feb 5 at 10:09
add a comment |
I was working on Firebase silent push notification using nodejs. When I tried below code its was working fine. When I was adding "priority": "high" and "content_available": true it was giving below error.
Worked below code
const admin = require('firebase-admin');
const serviceAccount ="...."; //service account path
admin.initializeApp({
credential: admin.credential.cert(serviceAccount)
});
let fcmToken = "...."; // Your token
let message ={
"token": fcmToken,
"data": {
"updateApi": "activity"
}
}
admin.messaging().send(message)
.then((response) =>{
console.log('Successfully sent notification:', response);
})
.catch((error) =>{
console.log('Error while sending notification:', error);
});
Error when I added the priority and content_available in message object
{ code: 'messaging/invalid-argument',
message: 'Invalid JSON payload received. Unknown name "priority" at 'message': Cannot find field.nInvalid JSON payload received. Unknown name "content_available" at 'message': Cannot find field.' },
codePrefix: 'messaging' }
HAve you solved this?
– Shubham1164
Feb 1 at 18:10
1
Yes, Just don't pass priority and content_available in above message object
– Priy Ranjan
Feb 5 at 10:03
Then how to control the values of these. Where I can change priority and content_available values?
– Shubham1164
Feb 5 at 10:09
add a comment |
I was working on Firebase silent push notification using nodejs. When I tried below code its was working fine. When I was adding "priority": "high" and "content_available": true it was giving below error.
Worked below code
const admin = require('firebase-admin');
const serviceAccount ="...."; //service account path
admin.initializeApp({
credential: admin.credential.cert(serviceAccount)
});
let fcmToken = "...."; // Your token
let message ={
"token": fcmToken,
"data": {
"updateApi": "activity"
}
}
admin.messaging().send(message)
.then((response) =>{
console.log('Successfully sent notification:', response);
})
.catch((error) =>{
console.log('Error while sending notification:', error);
});
Error when I added the priority and content_available in message object
{ code: 'messaging/invalid-argument',
message: 'Invalid JSON payload received. Unknown name "priority" at 'message': Cannot find field.nInvalid JSON payload received. Unknown name "content_available" at 'message': Cannot find field.' },
codePrefix: 'messaging' }
I was working on Firebase silent push notification using nodejs. When I tried below code its was working fine. When I was adding "priority": "high" and "content_available": true it was giving below error.
Worked below code
const admin = require('firebase-admin');
const serviceAccount ="...."; //service account path
admin.initializeApp({
credential: admin.credential.cert(serviceAccount)
});
let fcmToken = "...."; // Your token
let message ={
"token": fcmToken,
"data": {
"updateApi": "activity"
}
}
admin.messaging().send(message)
.then((response) =>{
console.log('Successfully sent notification:', response);
})
.catch((error) =>{
console.log('Error while sending notification:', error);
});
Error when I added the priority and content_available in message object
{ code: 'messaging/invalid-argument',
message: 'Invalid JSON payload received. Unknown name "priority" at 'message': Cannot find field.nInvalid JSON payload received. Unknown name "content_available" at 'message': Cannot find field.' },
codePrefix: 'messaging' }
answered Nov 22 '18 at 6:45
Priy RanjanPriy Ranjan
5617
5617
HAve you solved this?
– Shubham1164
Feb 1 at 18:10
1
Yes, Just don't pass priority and content_available in above message object
– Priy Ranjan
Feb 5 at 10:03
Then how to control the values of these. Where I can change priority and content_available values?
– Shubham1164
Feb 5 at 10:09
add a comment |
HAve you solved this?
– Shubham1164
Feb 1 at 18:10
1
Yes, Just don't pass priority and content_available in above message object
– Priy Ranjan
Feb 5 at 10:03
Then how to control the values of these. Where I can change priority and content_available values?
– Shubham1164
Feb 5 at 10:09
HAve you solved this?
– Shubham1164
Feb 1 at 18:10
HAve you solved this?
– Shubham1164
Feb 1 at 18:10
1
1
Yes, Just don't pass priority and content_available in above message object
– Priy Ranjan
Feb 5 at 10:03
Yes, Just don't pass priority and content_available in above message object
– Priy Ranjan
Feb 5 at 10:03
Then how to control the values of these. Where I can change priority and content_available values?
– Shubham1164
Feb 5 at 10:09
Then how to control the values of these. Where I can change priority and content_available values?
– Shubham1164
Feb 5 at 10:09
add a comment |
Please follow the documentation for server side and make setup for json as explained over the document. I have faced similiar problem earlier and solved the issue going this doc.
{
"to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"priority" : "high",
"notification" : {
"body" : "This week's edition is now available.",
"title" : "NewsMagazine.com",
"icon" : "new"
},
"data" : {
"volume" : "3.21.15",
"contents" : "http://www.news-magazine.com/world-week/21659772"
}
}
you were missing notification key. which is used by apns to get notification on background.
5
But I don't want the user to receive a notification in the Notification Center. I just want a silent notification that will execute some code in the "didReceiveRemoteNotification". That's what "silent notification" means.
– vladiulianbogdan
Nov 25 '16 at 15:18
add a comment |
Please follow the documentation for server side and make setup for json as explained over the document. I have faced similiar problem earlier and solved the issue going this doc.
{
"to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"priority" : "high",
"notification" : {
"body" : "This week's edition is now available.",
"title" : "NewsMagazine.com",
"icon" : "new"
},
"data" : {
"volume" : "3.21.15",
"contents" : "http://www.news-magazine.com/world-week/21659772"
}
}
you were missing notification key. which is used by apns to get notification on background.
5
But I don't want the user to receive a notification in the Notification Center. I just want a silent notification that will execute some code in the "didReceiveRemoteNotification". That's what "silent notification" means.
– vladiulianbogdan
Nov 25 '16 at 15:18
add a comment |
Please follow the documentation for server side and make setup for json as explained over the document. I have faced similiar problem earlier and solved the issue going this doc.
{
"to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"priority" : "high",
"notification" : {
"body" : "This week's edition is now available.",
"title" : "NewsMagazine.com",
"icon" : "new"
},
"data" : {
"volume" : "3.21.15",
"contents" : "http://www.news-magazine.com/world-week/21659772"
}
}
you were missing notification key. which is used by apns to get notification on background.
Please follow the documentation for server side and make setup for json as explained over the document. I have faced similiar problem earlier and solved the issue going this doc.
{
"to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"priority" : "high",
"notification" : {
"body" : "This week's edition is now available.",
"title" : "NewsMagazine.com",
"icon" : "new"
},
"data" : {
"volume" : "3.21.15",
"contents" : "http://www.news-magazine.com/world-week/21659772"
}
}
you were missing notification key. which is used by apns to get notification on background.
answered Nov 25 '16 at 15:00
rjndrarjndra
889
889
5
But I don't want the user to receive a notification in the Notification Center. I just want a silent notification that will execute some code in the "didReceiveRemoteNotification". That's what "silent notification" means.
– vladiulianbogdan
Nov 25 '16 at 15:18
add a comment |
5
But I don't want the user to receive a notification in the Notification Center. I just want a silent notification that will execute some code in the "didReceiveRemoteNotification". That's what "silent notification" means.
– vladiulianbogdan
Nov 25 '16 at 15:18
5
5
But I don't want the user to receive a notification in the Notification Center. I just want a silent notification that will execute some code in the "didReceiveRemoteNotification". That's what "silent notification" means.
– vladiulianbogdan
Nov 25 '16 at 15:18
But I don't want the user to receive a notification in the Notification Center. I just want a silent notification that will execute some code in the "didReceiveRemoteNotification". That's what "silent notification" means.
– vladiulianbogdan
Nov 25 '16 at 15:18
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f40807397%2ffirebase-fcm-silent-push-notifications-for-ios%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown