简体   繁体   English

成功发送到设备后,Firebase云消息传递不起作用

[英]Firebase cloud messaging does not work after successfully sendToDevice

I use Firebase Cloud Functions for sending notification via Cloud Messaging to iOS device. 我使用Firebase Cloud Functions通过Cloud Messaging将通知发送到iOS设备。 sendToDevice method works great and returns success promise without any error or warning in Firebase Functions logs, but on iOS, notification is not showed. sendToDevice方法的效果很好,可以在Firebase Functions日志中返回成功承诺,而不会出现任何错误或警告,但是在iOS上,不会显示通知。 If I send notification from Firebase Notifications dashboard, it works great and notification is showed on the device. 如果我从Firebase通知仪表板发送通知,则该通知会很好地工作并且通知会显示在设备上。 I don't know where I can have bug. 我不知道在哪里可以找到错误。 It's possible that bug is on iOS app side, even when it works like I said? 即使我像我说的那样工作,该错误也可能在iOS应用程序方面?

Firebase configuration: Firebase配置:

 var functions = require('firebase-functions');
 var admin = require('firebase-admin');
 var config = functions.config();
 admin.initializeApp(functions.config().firebase);

Part of cloud function: 云功能的一部分:

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);
        });

})

Firebase Cloud Functions log: Firebase云功能日志:

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

I wrote to Firebase Support and problem was with message type. 我写信给Firebase支持,问题出在消息类型上。 In Firebase we have two types of messages: data and notification. 在Firebase中,我们有两种消息类型:数据和通知。 In this case we should use type notification ( see documentation ). 在这种情况下,我们应该使用类型通知( 请参阅文档 )。

Payload should looks like this: 有效负载应如下所示:

var payload = {
    notification: {
        title: options.title,
        body: options.text,
    },
    data: {
        type: options.type,
    }
};

I think it is a issue with your payload. 我认为这与您的有效载荷有关。

Try this payload once with your firebase function, and let me know if you received notification on iOS. 使用您的firebase函数尝试一次此有效负载,并让我知道您是否在iOS上收到通知。

var payload = {
        data: {
            title: "Welcome to My Group",
            message: "You have new messages"
        }
    };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 调用Firebase Cloud Messaging sendToDevice时程序不会退出 - Program won't exit when call to Firebase Cloud Messaging sendToDevice Firebase 云消息 sendToDevice 工作正常,但 sendMulticast 对相同的令牌列表失败 - Firebase cloud messaging sendToDevice works properly but sendMulticast fails for the same list of tokens Firebase云消息传递requireInteraction不起作用 - Firebase Cloud Messaging requireInteraction not work TypeError: admin.messaging.sendToDevice is not a function ,使用 firebase 函数 - TypeError: admin.messaging.sendToDevice is not a function , using firebase functions Firebase云消息传递应该适用于移动设备吗? - Is Firebase Cloud Messaging supposed to work on mobile devices? VueJS Firebase云消息传递 - VueJS Firebase cloud messaging 为什么messaging().sendtodevice 有时不工作? - why messaging().sendtodevice is not working sometimes? 单击通知后如何访问通知数据(firebase 云消息传递) - How to access notification data after clicking on notification (firebase cloud messaging) firebase 云消息传递给 A bad HTTP 响应代码 (404) 单击“允许”并手动添加服务工作者不起作用 - firebase cloud messaging gives A bad HTTP response code (404) after clicking on 'allow' and adding service worker manually doesn't work 消息后来自 Firebase 云消息传递的 408 超时 - 408 timeout from Firebase Cloud Messaging after the message
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM