从云功能发送通知时未触发FirebaseMessaging回调

时间:2018-12-03 20:32:39

标签: firebase flutter firebase-cloud-messaging google-cloud-functions

客户端代码

final FirebasebaseMessaging _firebaseMessaging = new FirebaseMessaging();

   _firebaseMessaging.configure(onMessage: (Map<String,dynamic> notification){
    print("onMessage : $notification");
}, onResume: (Map<String,dynamic> notification){{
    print("onResume: $notification");
}}, onLaunch: (Map<String,dynamic> notification){
    print("onLaunch: $notification");
});
_firebaseMessaging.getToken().then((String token){
    print("token is : $token");
});

服务器端

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

  const payload = {
        "notification": {
            "body": postingUserDocumentSnapshot.data()['username'] + " commented on your post",
            "title": "You got a comment",
            "sound": 'enabled',
        },
        "data": {
            "click_action": "FLUTTER_NOTIFICATION_CLICK",
            "senderId": postingUserDocumentSnapshot.data()['userId'],
            "postID": context.params.postId,
            "notificationType": "COMMENT",
        },
    };
admin.messaging().sendToDevice(receiverMessagingToken, payload);

我确实在系统任务栏中收到通知,但未触发firebaseMessaging回调。但是,如果我从Google控制台发送通知,则会触发这些回调。 谁能解释我或建议我为什么通过admin.messaging().sendToDevice发送通知时未触发这些回调?

0 个答案:

没有答案
相关问题