启动时触发FCM,在Android上运行良好以下是用于处理FCM的代码。iOS通知是在后台应用程序和打开单击应用程序时触发的。
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
print(message);
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
new FlutterLocalNotificationsPlugin();
// initialise the plugin. app_icon needs to be a added as a drawable resource to the Android head project
var initializationSettingsAndroid =
new AndroidInitializationSettings('launcher_icon');
var initializationSettingsIOS = new IOSInitializationSettings(
onDidReceiveLocalNotification: onDidReceiveLocalNotification);
var initializationSettings = new InitializationSettings(
initializationSettingsAndroid, initializationSettingsIOS);
flutterLocalNotificationsPlugin.initialize(initializationSettings,
onSelectNotification: onSelectNotification);
var androidPlatformChannelSpecifics = AndroidNotificationDetails(
'123', 'convoy notification', 'convoy notification',
importance: Importance.Max,
priority: Priority.High,
ticker: 'ticker');
var iOSPlatformChannelSpecifics = IOSNotificationDetails();
var platformChannelSpecifics = NotificationDetails(
androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
await flutterLocalNotificationsPlugin.show(
0,
message['notification']['title'],
message['notification']['body'],
platformChannelSpecifics,
payload: message['data']['payload']);
},
onBackgroundMessage: myBackgroundMessageHandler,
onLaunch: (Map<String, dynamic> message) async {
var string = message["data"]["payload"];
var payload = jsonDecode(string);
print(payload);
if (payload != null) {
var type = payload["refresh"];
if (type == "OFFERS") {
Future.delayed(Duration(seconds: 3), () {
_navigateToOffers(payload["id"]);
});
} else if (type == "REQUESTS") {
Future.delayed(Duration(seconds: 3), () {
_navigateToRequests(payload["id"]);
});
}
}
//_navigateToItemDetail(message);
},
onResume: (Map<String, dynamic> message) async {
var string = message["data"]["payload"];
var payload = jsonDecode(string);
print(payload);
if (payload != null) {
var type = payload["refresh"];
if (type == "OFFERS") {
_navigateToOffers(payload["id"]);
} else if (type == "REQUESTS") {
_navigateToRequests(payload["id"]);
}
}
// _navigateToItemDetail(message);
},
);
_firebaseMessaging.requestNotificationPermissions(
const IosNotificationSettings(sound: true, badge: true, alert: true));
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。