android - 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)
}
})
解决方案
我未获得授权的原因是我Team ID
在 Firebase 项目设置中的 ID 与在Apple Developer Console
. 一旦我确定这些是相等的并再次完成该过程,我就能够成功获得通知。
推荐阅读
- java - 如何找出 WorkManager 更改了哪些标记的工作状态?
- c# - 如何在 ListView 中为 Xamarin Forms 绑定一个简单的标签?
- rxjs - 用 RXJS 实现一个 http 请求队列
- winappdriver - 如何在 Win App 驱动程序中启动单击一次应用程序?
- javascript - 使用 Stripe Payment Intent 自定义支付流程传递额外的客户详细信息
- javascript - 如何在 axios [REACT, EXPRESS,NODE JS] 中访问 403 的响应 statusText
- python-3.x - 未找到模块错误:没有模块名称 matplotlib
- json - 在 sed 中减法我在哪里犯了错误?
- awk - 使用 awk 解析在 CRLF 之前有 8 个二进制字符的文件
- java - Java 集合接口动态调度