After checking this similar question and another, I am still unable to send messages to my iOS device.
I am sending messages via my Firebase Cloud Functions
which is working correctly for android but for iOS devices I receive this error in the end: A message targeted to an iOS device could not be sent because the required APNs SSL certificate was not uploaded or has expired. Check the validity of your development and production certificates
.
I have confirmed that I do have the proper certificates under Push Notifications
And within my Firebase Project Settings, I have also added my APN Key here from the Apple Dev Console.
I have done this process 3 times already and it still is not working appropriately.
To confirm, here is my code for cloud functions
const functions = require("firebase-functions");
const admin = require('firebase-admin')
const { CloudTasksClient } = require('@google-cloud/tasks');
const serviceAccount = require('./serviceAccountKey.json');
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://[project-id].firebaseio.com"
})
exports.firestoreTtlCallback = functions.https.onRequest(async (req, res) => {
try {
const payload = req.body;
let entry = await (await admin.firestore().doc(payload.docPath).get()).data();
let tokens = await (await admin.firestore().doc(`/users/${payload.uid}`).get()).get('tokens')
const notification = {
notification: {
title: 'App',
body: entry['text']
}
}
const response = await admin.messaging().sendToDevice(
tokens,
notification
)
response.results.forEach((result, index) => {
const error = result.error;
if (error) {
functions.logger.error('Failure sending notification to', tokens[index],
error)
if (error.code === 'messaging/invalid-registration-token' || error.code === 'messaging/registration-token-not-registered') {
// remove token here
}
} else {
log("Successfully send message!")
}
})
await admin.firestore().doc(payload.docPath).update({ expirationTask: admin.firestore.FieldValue.delete() })
res.sendStatus(200)
} catch (err) {
log(err)
await admin.firestore().doc(payload.docPath).update({ expirationTask: admin.firestore.FieldValue.delete() })
res.status(500).send(err)
}
})