FCM Push Notification is not received when the Flutter app runs on IOS devices. Once the app goes in the background or is minimized, the Push notification works properly.
I have used firebase_messaging and flutter_local_notifications plugins for this.
initialize() async {
FirebaseMessaging messaging = FirebaseMessaging.instance;
SharedPreferences sharedPreferences = await
SharedPreferences.getInstance();
NotificationSettings settings = await messaging.requestPermission(
alert: true,
announcement: false,
badge: true,
carPlay: false,
criticalAlert: false,
provisional: false,
sound: true,
);
if (settings.authorizationStatus == AuthorizationStatus.authorized) {
print('User granted permission');
} else if (settings.authorizationStatus ==
AuthorizationStatus.provisional) {
print('User granted provisional permission');
} else {
print('User declined or has not accepted permission');
}
messaging.getToken().then((token) {
print("FCM TOKEN:- $token");
sharedPreferences.setString("fcmToken", token.toString());
});
FirebaseMessaging.onMessage.listen((RemoteMessage event) {
print("message received");
print(event.notification!.body);
flutterLocalNotificationsPlugin.show(
1,
event.notification!.title.toString(),
event.notification!.body.toString(),
NotificationDetails(
android: AndroidNotificationDetails(
channel.id,
channel.name,
color: Colors.amber,
playSound: true,
icon: '@mipmap/ic_launcher',
),
));
});
FirebaseMessaging.onMessageOpenedApp.listen((message) {
print('Message clicked!');
});
}
Can anyone please help me out?
2
Answers
When you are listen notification in onMessage,You have added only android specification. please add IOS specification as well.
If you mean that you are not receiving while the app in foreground you need to add this