I've an app based on react native with expo. For push notifications, i'm trying to use firebase. I've created functions in firebase and tried to send notification from firebase to my iphone. I don't see any issues in the code and verified firebase log too. Getting status "ok" message after this function triggered but still i didn't get notifications in my mobile. Anyone can help?
I'm in firebase paid plan. Same code is firing notification when i run directly from react native app.
const functions = require("firebase-functions");
const fetch = require("node-fetch");
const admin = require("firebase-admin");
admin.initializeApp(functions.config().firebase);
exports.sendPushNotification = functions.database
.ref("orders/{id}")
.onCreate((snapshot, context) => {
var messages = [];
const root = admin.database().ref("customers");
console.log("customers : " + root.path);
return root
.once("value")
.then((snapshot) => {
snapshot.forEach((childSnapshot) => {
//alert(expoToken);
var expoToken = childSnapshot.val().expoPushToken;
console.log("token : " + expoToken);
if (expoToken) {
messages.push({
to: expoToken,
title: "hello",
body: "New Order",
});
}
});
return Promise.all(messages);
})
.then((messages) => {
const res = fetch("https://exp.host/--/api/v2/push/send", {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
body: JSON.stringify(messages),
});
console.log(res);
return res;
});
});