我正在我的 Flutter 项目中使用 FCM。当应用程序在前台并从 FCM 接收到通知时,我想显示一个 AlertDialog。这个功能在 Android 上可以工作,但在 iOS 上无法正常工作。有谁能帮助我吗?
以下是我的代码片段:
FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
print("FCM: onMessage: " + message['notification']['body']);
//showNotification(message['notification']['title'], message['notification']['body']);
print("FCM: onMessage: $message");
setState(() {
return notification = true;
});
AwesomeDialog(
context: scaffoldKey.currentContext,
title: message['notification']['title'],
desc: message['notification']['body'],
btnOkOnPress: () {
Navigator.pop(scaffoldKey.currentState.context);
},
).show();
//notification sound
playSound();
},
onLaunch: (Map<String, dynamic> message) async {
print("FCM: onLaunch: $message");
},
onResume: (Map<String, dynamic> message) async {
print("FCM: onResume: $message");
},
);
_firebaseMessaging.requestNotificationPermissions(
const IosNotificationSettings(sound: true, badge: true, alert: true));
_firebaseMessaging.onIosSettingsRegistered
.listen((IosNotificationSettings settings) {
print("Settings registered: $settings");
});