iOS 使用 Cloud Functions 的后台通知
iOS background notifications using Cloud Functions
我在应用进入后台时获取数据时遇到问题。我正在使用 Firebase Cloud 函数,我认为我在 NodeJS 中没有正确编码。我尝试了很多例子和解决方案,比如:
content_available: true
和 priority: 'high'
但似乎没有任何效果。我必须注意:
Notifications are arriving in background and foreground but I can read data from notification in foreground but data is not fetched in background. So there is NO notifications data in background even it is displayed with sound and alert.
我认为我在数据负载方面做错了,所以这是我的 NodeJS 方法:
var message = {
token: tokenID,
notification: {
title: 'ChatApplication',
body: `${myUsername} send you a message`,
},
android: {
ttl: 3600 * 1000,
notification: {
icon: 'default',
sound: 'default',
click_action: "com.yupi.chatapplication.messaging"
},
data: {
from_user: user_id,
title: 'ChatApplication',
body: `${myUsername} send you a message`
},
},
apns: {
payload: {
aps: {
alert: {
title: 'ChatApplication',
body: `${myUsername} send you a message`
},
badge: 1,
sound: 'default',
content_available: true,
mutable_content: true,
priority: 'high'
},
},
},
};
return admin.messaging().send(message)
.then((response) => {
// Response is a message ID string.
return console.log('Successfully sent message:', response);
})
.catch((error) => {
return console.log('Error sending message:', error);
});
Node.js SDK 的正确字段名称应为 contentAvailable
和 mutableContent
:https://firebase.google.com/docs/reference/admin/node/admin.messaging.Aps
我在应用进入后台时获取数据时遇到问题。我正在使用 Firebase Cloud 函数,我认为我在 NodeJS 中没有正确编码。我尝试了很多例子和解决方案,比如:
content_available: true
和 priority: 'high'
但似乎没有任何效果。我必须注意:
Notifications are arriving in background and foreground but I can read data from notification in foreground but data is not fetched in background. So there is NO notifications data in background even it is displayed with sound and alert.
我认为我在数据负载方面做错了,所以这是我的 NodeJS 方法:
var message = {
token: tokenID,
notification: {
title: 'ChatApplication',
body: `${myUsername} send you a message`,
},
android: {
ttl: 3600 * 1000,
notification: {
icon: 'default',
sound: 'default',
click_action: "com.yupi.chatapplication.messaging"
},
data: {
from_user: user_id,
title: 'ChatApplication',
body: `${myUsername} send you a message`
},
},
apns: {
payload: {
aps: {
alert: {
title: 'ChatApplication',
body: `${myUsername} send you a message`
},
badge: 1,
sound: 'default',
content_available: true,
mutable_content: true,
priority: 'high'
},
},
},
};
return admin.messaging().send(message)
.then((response) => {
// Response is a message ID string.
return console.log('Successfully sent message:', response);
})
.catch((error) => {
return console.log('Error sending message:', error);
});
Node.js SDK 的正确字段名称应为 contentAvailable
和 mutableContent
:https://firebase.google.com/docs/reference/admin/node/admin.messaging.Aps