Firebase FCM silent push notifications for iOS

后端 未结 4 1771
花落未央
花落未央 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: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' }
    

提交回复
热议问题