我正在为我的react原生应用程序开发好友请求功能,如果请求被接受,我想使用云消息通知用户(发送者)。它在安卓上工作成功,我在设备上收到通知,但它不能工作的iOS。
这是我的接受好友请求的云函数:
//======================ACCEPT REQUEST==========================//
exports.onAcceptRequest = functions.https.onCall((data, context) => {
const targetId = data.targetId;
const senderId = data.senderId;
return admin
.firestore()
.collection('Friendships')
.doc()
.set({
targetId: targetId,
senderId: senderId,
timeStamp: new Date(),
})
.then(() => {
console.log('Befriended');
notifySenderId(senderId);
return null;
//NOTIFICATION SENT TO uid2(senderId)
})
.catch(err => console.log('errrrrr', err));
});
function notifySenderId(senderId) {
return admin
.firestore()
.collection('Users')
.doc(`${senderId}`)
.get()
.then(doc => {
var tokens = Object.keys(doc.data().fcmTokens);
console.log('TOKENS: ', tokens);
return tokens;
})
.then(tokens => {
console.log('tokens: ', tokens);
const payload = {
notification: {
title: 'Friend Request Accepted',
body: 'Hi add me to a group',
sound: 'default',
},
};
return admin.messaging().sendToDevice(tokens, payload);
})
.then(() => console.log('notified senderId of Acceptance'))
.catch(err => console.log('err notifying senderId', err));
}在iOS上,云函数可以在后端成功执行(如下面的函数日志所示),但不会在设备上显示通知,即使我在设置中允许了通知。
我没有使用任何库来显示通知。我希望FCM能自动显示通知消息(适用于android)。
云函数日志:

编辑:解决了它!我了解到fcmTokens可能会随着时间的推移而改变,更新数据库中的令牌解决了我的问题。
但我有一个后续问题,我们如何跟踪设备上的令牌更新?
发布于 2019-12-01 08:28:42
解决了!我了解到fcmTokens可能会随着时间的推移而改变,更新数据库中的令牌解决了我的问题。
https://stackoverflow.com/questions/59121440
复制相似问题