1

Ich kann Push-Benachrichtigungen von Firebase Console Notifications an mein iOS-Gerät senden, und es funktioniert perfekt, die App im Vordergrund und im Hintergrund.Firebase-Admin sendet keine iOS-APN-Benachrichtigung

Wenn ich versuche, sie mit Firebase-admin by NodeJS zu senden, funktioniert es nur, wenn die App im Vordergrund ist, im Hintergrund passiert nichts.

Ich denke, dass die Kommunikation zwischen FCM-APNs gut sind, weil es mit der Konsole funktioniert.

Das ist mein NodeJS Code:

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); 
     }); 
} 

Was denken Sie, dass es passiert? Kennen Sie eine Möglichkeit, das Problem zu protokollieren?

Antwort

1

Die Server Protocol documentation zeigt an, dass der Schlüssel für den Benachrichtigungstext body ist, nicht text. Sehen Sie, wenn diese Änderung einen Unterschied macht:

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

Vielen Dank !. Es gab zwei Fehler. Zuerst die, die du gesagt hast. Zweitens war der Firebase JSON schlecht :(. Zu viele Stunden entwickeln sich ... – Georgevik