我正在尝试使用 Firebase 云功能向另一台 iOS 设备发送推送通知,但在尝试执行此操作时收到以下错误:
'FirebaseMessagingError:提供的注册令牌无效。确保它与客户端应用通过 FCM 注册收到的注册令牌匹配。'
这是我尝试发送到 6e04bb35f06e2d981d5603bbd229eeab5ee5649f6af7b4ecc3894be6ad1574d7 的注册令牌,它与我保存在实时数据库中的令牌相同:
下面是我的 onCreate 函数:
exports.onMessageCreate = functions.database.ref('/messages/{chatId}/{messageId}').onCreate((snapshot, context) => {
const chatId = context.params.chatId;
const receiverId = chatId.replace(context.auth.uid, '');
const root = snapshot.ref.root;
return admin.database().ref(`/users/${receiverId}/regToken`).once('value').then(tokenSnap => {
var regTokenRef = tokenSnap.val();
const payload = {
notification: {
title: 'title',
body: snapshot.val().text,
}
};
const options = { priority: "high" };
return admin.messaging().sendToDevice(regTokenRef, payload, options).then(function(response){
console.log("Successfully sent message: ", response);
console.log(response.results[0].error);
}).catch(function(error) {
console.log("Error sending message: ", error);
});
});
});
你知道是什么导致了这个错误吗?我不太确定我需要在这里检查什么。这里格式不对吗?它需要在引号中吗?我查看了其他链接,但它们并没有真正帮助。
我正在导入“@react-native-community/push-notification-ios”来生成令牌。我认为这可能是问题所在。我在使用来自 firebase 的消息传递时遇到问题。这是问题吗?
请参阅下面在我的 AppDelegate.m 文件中更新的 didFinishLaunchingWithOptions 方法。我是否正确放置了以下代码?添加此项后,它会导致我的应用在启动模拟器时显示为空白,并显示 FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app).?但是,删除后我的应用程序启动但仍然有 FirebaseError。
if ([FIRApp defaultApp] == nil) {
[FIRApp configure];
}
答案 0 :(得分:0)
@react-native-community/push-notification-ios 无法生成 FCM 令牌,只能生成 APN 令牌:https://github.com/react-native-push-notification-ios/push-notification-ios/issues/117
如果你想使用firebase,你需要从firebase的消息包中生成令牌才能拥有一个FCM。