代码之家  ›  专栏  ›  技术社区  ›  ujjwal mainali

从云函数发送通知时未触发FirebaseMessaging回调

  •  0
  • ujjwal mainali  · 技术社区  · 6 年前

    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 回复  |  直到 6 年前