客户端代码
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
发送通知时未触发这些回调?