FCM Push Notification not working in Flutter App for IOS devices


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?

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img