0

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 enter image description here

And within my Firebase Project Settings, I have also added my APN Key here from the Apple Dev Console. enter image description here

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)
    }
})
pythonNovice
  • 1,130
  • 1
  • 14
  • 36

1 Answers1

0

The reason why I was not getting authorized is because my Team ID in my Firebase Project Settings was not the same ID that created in the Apple Developer Console. Once I made sure that these were equal and went through the process once more, I was able to get notifications successfully.

pythonNovice
  • 1,130
  • 1
  • 14
  • 36