启动时恢复和在iOS上无法正常工作的消息上打振FCM启动时触发dart服务,在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));
}
答案 0 :(得分:0)
尝试在ios / Runner / AppDelegate.swift中删除这些行:
if #available(iOS 10.0, *) { UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate }
我遇到同样的问题,删除此代码后,我的应用程序运行良好。