首页 > 解决方案 > Firebase 消息:由于所需的 APNs SSL 证书已过期或未上传,无法向 iOS 设备发送消息

问题描述

在检查了这个类似的问题另一个之后,我仍然无法向我的 iOS 设备发送消息。

我正在通过 my 发送消息,Firebase Cloud Functions这对于 android 可以正常工作,但对于 iOS 设备,我最终收到此错误: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.

我已确认我在推送通知下确实拥有适当的证书 在此处输入图像描述

在我的 Firebase 项目设置中,我还从 Apple Dev Console 添加了我的 APN 密钥。 在此处输入图像描述

我已经完成了 3 次此过程,但仍然无法正常工作。

为了确认,这是我的代码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)
    }
})

标签: androidiosfirebasesslfirebase-cloud-messaging

解决方案


我未获得授权的原因是我Team ID在 Firebase 项目设置中的 ID 与在Apple Developer Console. 一旦我确定这些是相等的并再次完成该过程,我就能够成功获得通知。


推荐阅读