我使用Firebase雲端函數通過Cloud Messaging向iOS設備發送通知。 sendToDevice
方法工作良好,並且返回成功承諾,但Firebase函數日誌中沒有任何錯誤或警告,但在iOS上不顯示通知。如果我通過Firebase通知信息中心發送通知,該通知很有用,並且會在設備上顯示通知。我不知道我在哪裏可以有bug。這個錯誤可能在iOS應用程序端,即使它像我說的那樣工作?成功sendToDevice後Firebase雲消息傳遞不起作用
火力地堡配置:
var functions = require('firebase-functions');
var admin = require('firebase-admin');
var config = functions.config();
admin.initializeApp(functions.config().firebase);
雲功能的部分:
APP.services.firebase.admin.database().ref('tokens/' + userId).once('value', function(snapshot) {
var userDevicesTokens = [];
snapshot.forEach(function(childSnapshot) {
userDevicesTokens.push(childSnapshot.key)
});
if (userDevicesTokens.length === 0) {
console.warn('No tokens for user');
return;
}
var payload = {
data: {
title: options.title,
text: options.text,
type: options.type,
}
};
APP.services.firebase.admin.messaging().sendToDevice(userDevicesTokens, payload)
.then(function(response) {
console.log("Successfully sent message:", response);
})
.catch(function(error) {
console.log("Error sending message:", error);
});
})
火力地堡雲功能登錄:
11: 52: 43.952 AM info newChatMessageTrigger
Successfully sent message: {
results: [{
messageId: '0:15016....'
}],
canonicalRegistrationTokenCount: 0,
failureCount: 0,
successCount: 1,
multicastId: 589....
}
11: 52: 22.760 AM outlined_flag newChatMessageTrigger
Function execution took 604 ms, finished with status: 'ok'
11: 52: 22.252 AM outlined_flag newChatMessageTrigger
Billing account not configured.External network is not accessible and quotas are severely limited.Configure billing account to remove these restrictions
11: 52: 22.252 AM outlined_flag newChatMessageTrigger
Function execution started
您是否嘗試發送'notification'消息有效呢? –