我正在使用此库。
我正在尝试获取在Nexus 5(Android 6.0.1)上的通知托盘中显示的推送通知。使用反应天然0.42,反应本机CLI 2.0.1。我在Ubuntu 14.04。
上开发我正在使用firebase。我进入控制台>通知>发送消息>特定设备(我从远程调试台。
我正在记录通知,如您在代码中所看到的,它们确实可以进入我的设备,因为我可以在日志中看到它们。
但是,我不知道如何在通知托盘中显示它们。浏览文档和搜索论坛,似乎默认情况下应该显示。
componentDidMount() {
FCM.requestPermissions(); // for iOS
FCM.getFCMToken().then(token => {
console.log(token)
// store fcm token in your server
});
this.notificationListener = FCM.on(FCMEvent.Notification, async (notif) => {
console.log(notif)
});
});
似乎需要" custom_notification"才能在顶部托盘中显示通知。我将其添加到有效载荷中:
" custom_notification":{ "身体":"测试身体", "标题":"测试标题", "颜色":"#00acd4", "优先":"高", "图标":" ic_notif", " group":" group", " id":" id", " show_in_foreground":正确 }
因此,我认为该应用必须收到通知,解析数据并添加此custom_notification参数。
构造函数中的以下内容:
FCM.requestPermissions(); // for iOS
FCM.getFCMToken().then(token => {
console.log(token)
// store fcm token in your server
});
this.notificationListener = FCM.on(FCMEvent.Notification, async (notif) => {
// do some component related stuff
console.log(notif);
//alert(notif.fcm.body);
FCM.presentLocalNotification({
id: "UNIQ_ID_STRING", // (optional for instant notification)
title: "My Notification Title", // as FCM payload
body: notif.fcm.body, // as FCM payload (required)
sound: "default", // as FCM payload
priority: "high", // as FCM payload
click_action: "ACTION", // as FCM payload
badge: 10, // as FCM payload IOS only, set 0 to clear badges
number: 10, // Android only
ticker: "My Notification Ticker", // Android only
auto_cancel: true, // Android only (default true)
large_icon: "ic_launcher", // Android only
icon: "ic_launcher", // as FCM payload, you can relace this with custom icon you put in mipmap
big_text: "Show when notification is expanded", // Android only
sub_text: "This is a subText", // Android only
color: "red", // Android only
vibrate: 300, // Android only default: 300, no vibration if you pass null
tag: 'some_tag', // Android only
group: "group", // Android only
picture: "https://google.png", // Android only bigPicture style
ongoing: true, // Android only
my_custom_data: 'my_custom_field_value', // extra data you want to throw
lights: true, // Android only, LED blinking (default false)
show_in_foreground: true // notification when app is in foreground (local & remote)
});
});
FCM.subscribeToTopic('test_topic');