【发布时间】:2020-05-08 15:36:23
【问题描述】:
编辑:此问题已在最新的颤振和 firebase 版本上得到修复。
我正在收听 Firebase FCM data 类型的消息,并且在接收 FCM 消息时,我打算在应用内显示本地通知。
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
print('on message $message');
LocalNotificationService.showNotoficationWithDefaultSound("onmessage");
},
onResume: (Map<String, dynamic> message) async {
LocalNotificationService.showNotoficationWithDefaultSound("onresume");
print('on resume $message');
},
onLaunch: (Map<String, dynamic> message) async {
LocalNotificationService.showNotoficationWithDefaultSound("onlaunch");
print('on launch $message');
},
onBackgroundMessage: myBackgroundMessageHandler,
);
/// Yes. This is a global function
Future<dynamic> myBackgroundMessageHandler(Map<String, dynamic> message) {
var androidPlatformChannelSpecifics = new AndroidNotificationDetails(
'chanID_007', 'chanName_kk107', 'This is my channel');
var iosPlatformChannelSpecifics = new IOSNotificationDetails();
var platformChannelSpecifics = new NotificationDetails(
androidPlatformChannelSpecifics, iosPlatformChannelSpecifics);
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin;
var initializationSettingsAndroid =
new AndroidInitializationSettings('@mipmap/ic_launcher');
var initializationSettingsIos = new IOSInitializationSettings();
var initializationSettings = new InitializationSettings(
initializationSettingsAndroid, initializationSettingsIos);
flutterLocalNotificationsPlugin = new FlutterLocalNotificationsPlugin();
flutterLocalNotificationsPlugin.initialize(initializationSettings,
onSelectNotification: onSelectNotification);
await flutterLocalNotificationsPlugin.show(
0, 'Tada!!', 'test', platformChannelSpecifics,
payload: 'payload#7');
print("background mssg");
}
但是使用 flutter_local_notification 插件显示本地通知会引发错误
Unhandled Exception: MissingPluginException(No implementation found for method initialize on channel dexterous.com/flutter/local_notifications)
我在这里错过了什么?
【问题讨论】:
-
在这里找到了解决方案。需要在android上的Application类中注册插件。 stackoverflow.com/a/59836752/5546443
标签: flutter firebase-cloud-messaging