I am having this issue where I can perfectly send push notifications with Firebase Cloud Messaging to Android but in iOS sometimes it works and sometimes not, with the same token. I realize that the message is always send, but the device sometimes does not receive it. The Apns is configured (since sometimes it works). The app is running in React Native
This is my code in node.js
import admin from 'firebase-admin'
import { getFirestore } from 'firebase-admin/firestore'
import fs from 'fs/promises';
const jsonContent = await fs.readFile('google-service.json', 'utf-8');
const data = JSON.parse(jsonContent);
import dotenv from 'dotenv'
dotenv.config()
admin.initializeApp({
credential: admin.credential.cert(data),
});
function showNotifications() {
const db = getFirestore();
const notificationsRef = db.collection('Properties');
// Set up a real-time listener with a query
notificationsRef
.where('last_tx_mod', '==', true)
.onSnapshot((snapshot) => {
snapshot.docChanges().forEach(async (change) => {
if (change.type === 'added') {
const userUid = change.doc.data().user;
const fcmToken = await getFCMToken(userUid);
await updateModTX(change.doc.id);
await sendNotification(fcmToken, '¡Sended!', 'message send');
}
});
});
}
async function sendNotification(fcmToken, title, body) {
try {
const response = await admin
.messaging()
.send({
notification: {
title,
body
},
token: fcmToken,
android: {
priority: 'high'
},
apns: {
headers: {
"apns-priority": "10"
}
},
webpush: {
headers: {
"Urgency": "high"
}
}
})
// console.log('Successfully sent message:', response);
} catch (error) {
console.log('Error sending message:', error);
throw Error(error.message)
}
}




