Firebase 当应用程序打开时(前台),当OnMessage被触发时,如何显示推送通知?
Im使用颤振和Firebase消息传递。 我即时配置Firebase,如示例所示:Firebase 当应用程序打开时(前台),当OnMessage被触发时,如何显示推送通知?,firebase,flutter,firebase-cloud-messaging,Firebase,Flutter,Firebase Cloud Messaging,Im使用颤振和Firebase消息传递。 我即时配置Firebase,如示例所示:firebaseMessaging.configure( onMessage:。。。 onLaunch:。。。 简历:。。。 ) 但我想看到推送通知,即使应用程序是打开的 粗略地说,onMessage应该像onResume一样工作我如何才能做到这一点?onMessage:(映射消息)异步{ onMessage: (Map<String, dynamic> message) async {
firebaseMessaging.configure(
onMessage:。。。
onLaunch:。。。
简历:。。。
)
但我想看到推送通知,即使应用程序是打开的
粗略地说,onMessage应该像onResume一样工作
我如何才能做到这一点?
onMessage:(映射消息)异步{
onMessage: (Map<String, dynamic> message) async {
showNotification(message);
print('on message $message');
}
showNotification(Map<String, dynamic> msg) async {
var android = new AndroidNotificationDetails(
'your channel id',//channel id
"your channel name",//channel name
"your channel description",//channel desc todo set all this right
icon: 'mipmap/launcher_icon'//add your icon here
);
var iOS = new IOSNotificationDetails();
var platform = new NotificationDetails(android, iOS);
await flutterLocalNotificationsPlugin
.show(0, msg['notification']['title'], msg['notification']['body'], platform);
}
显示通知(消息);
打印('on message$message');
}
showNotification(映射消息)异步{
var android=新的AndroidNotificationDetails(
“您的频道id”,//频道id
“您的频道名称”,//频道名称
“您的频道描述”//channel desc todo将所有这些设置为正确
图标:“mipmap/launcher\u icon”//在此处添加您的图标
);
var iOS=新的IONotificationDetails();
var平台=新通知详细信息(android、iOS);
等待通知
.show(0,消息['notification']['title'],消息['notification']['body'],平台);
}
我过去经常在前台显示本地通知
此外,如果您正在实施IOS,请不要忘记请求通知权限