我使用Flutter和Firebase消息。我像示例中那样配置Firebase:firebaseMessaging.configure(
onMessage: ...
onLaunch: ...
onResume: ...
)
但即使应用程序打开,我也希望看到推送通知
粗略地说,onMessage应该像onResume一样工作
我该怎么做?
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);
}
我使用flatter_local_notifications:^1.2.2来显示本地通知前台。
此外,如果您正在为IOS实现,请不要忘记请求通知权限。