我正在使用react-native-firebase用于FCM,当正确显示在后台通知弹出窗口中运行的应用时。但是当应用程序在前台运行时,没有显示通知。相同的代码适用于Android。使用以下代码
this.firebase.messaging().createLocalNotification({
title: 'Messenger',
body: "message",
icon: 'ic_launcher',
id: new Date().getTime()+"",
action: action,
screen: screen,
local_notification: true,
show_in_foreground: true,
_notificationType: 'local_notification',
opened_from_tray: false
});
答案 0 :(得分:0)
从react-native-fcm模块开始,有效负载必须包含以下键值对。
{
id: "UNIQ_ID_STRING", // (optional for instant notification)
title: "My Notification Title", // as FCM payload
body: "My Notification Message", // 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 0
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 // notification when app is in foreground (local & remote)
}
" show_in_foreground"必须提供,以便在您的应用运行时在前台显示本地通知。