简体   繁体   English

从 Node.js 管理员 SDK 到 Flutter 应用程序发送 FCM 通知时如何添加点击操作?

[英]How to add click action when sending FCM notification from Node.js admin SDK to Flutter app?

I have a cloud function which executes this code to send the notification to the user, I am getting notification correctly but I want to navigate to a particular screen for that I have to add click action something like this.我有一个云 function 执行此代码以将通知发送给用户,我得到了正确的通知,但我想导航到一个特定的屏幕,因为我必须添加类似这样的点击操作。

clickAction: FLUTTER_NOTIFICATION_CLICK I have tried to put this property in different lines of code but nothing seem to work, can someone please tell where should I put it exactly? clickAction: FLUTTER_NOTIFICATION_CLICK我试图将此属性放在不同的代码行中,但似乎没有任何效果,有人可以告诉我应该把它放在哪里吗? This is my index.js file!这是我的 index.js 文件!

const message = {
  token: data['guestFcmToken'],
  notification: {
    title: `New message from ${data['hostName']}.`,
    body: data['type'] === 'image' ? 'Photo' : data['lastMessage'],
  },
  data: {
    showForegroundNotification: 'false',
    screen: 'chat'
  },
}
console.log('Sending message');
const response = await admin.messaging().send(message);
console.log(response);

You can add clickAction: 'FLUTTER_NOTIFICATION_CLICK' in the following way您可以通过以下方式添加 clickAction: 'FLUTTER_NOTIFICATION_CLICK'

message = {
    token: data['guestFcmToken'],
    notification: {
        title: `New message from ${data['hostName']}.`,
        body: data['type'] === 'image' ? 'Photo' : data['lastMessage'],
    },
    data: {
        showForegroundNotification: 'false',
        screen: 'chat'
    },
    android: {
        notification: {
            clickAction: 'FLUTTER_NOTIFICATION_CLICK',
        },
    }
};

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM