1

我可以将推送通知从Firebase Console Notifications发送到我的iOS设备,它可以完美地作为前台和后台的应用程序。Firebase-admin不发送iOS APN通知

当我尝试使用Firebase-admin by NodeJS发送它们时,它只在应用程序处于前景时才起作用,在后台没有任何反应。

我认为FCM-APN之间的通信很好,因为它与控制台一起工作。

这是我的代码的NodeJS:

function sendFCM(registration_ids, data, collapseKey) { 

    const options = { 
     priority: "high", 
     collapseKey : collapseKey, 
     contentAvailable : true, 
     timeToLive: 60 * 60 * 24 
    }; 

    const payload = { 
     data: data, 
     notification: { 
      title: "My title", 
      text: "My description", 
      sound : "default" 
     } 
    } 

    admin.messaging().sendToDevice(registration_ids, payload, options) 
     .then(function(response) { 
      console.log("Successfully sent message:", response); 
     }) 
     .catch(function(error) { 
      console.log("Error sending message:", error); 
     }); 
} 

你觉得这是怎么回事?你知道一些方法来记录这个问题吗?

回答

1

Server Protocol documentation表示通知文本的关键是body而不是text。看看这个改变是否有所作为:

const payload = { 
    data: data, 
    notification: { 
     title: "My title", 
     body: "My description", // <= CHANGE 
     sound : "default" 
    } 
} 
+0

谢谢!有两次失败。首先,你说的那个。其次,firebase json很糟糕:(开发太多小时... – Georgevik