Firebase FCM silent push notifications for iOS

后端 未结 4 1757
花落未央
花落未央 2020-12-03 05:31

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 direc

相关标签:
4条回答
  • 2020-12-03 05:45

    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.

    0 讨论(0)
  • 2020-12-03 05:50

    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' }
    
    0 讨论(0)
  • 2020-12-03 05:52

    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",
      "content_available": true,
      "notification" : {
        "body" : "",
        "title" : "",
        "icon" : "new"
      },
      "data" : {
        "volume" : "3.21.15",
        "contents" : "http://www.news-magazine.com/world-week/21659772"
      }
    }
    

    content_available = true and body, title empty does the task.

    0 讨论(0)
  • 2020-12-03 05:59

    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

    0 讨论(0)
提交回复
热议问题