Flutter FCM push notification not receiving on IOS with firebase_messaging: ^9.1.3

Viewed 4662

I have tried every solution on StackOverflow and GitHub but I am still not receiving notifications in IOS. In android, it is working fine but in IOS, it is not. I am using the latest version of the firebase_messaging plugin i.e ^9.1.3 with the new functions they have introduced. Can anyone help, please? Below is the code I have used to get the notification data

I am testing this in real IOS device with version 14.2 and I have also enabled the notifications in settings.

 Future<void> _firebaseMessagingBackgroundHandler(
          RemoteMessage message) async {
        // If you're going to use other Firebase services in the background, such as Firestore,
        // make sure you call `initializeApp` before using other Firebase services.
        await Firebase.initializeApp();
        print('Handling a background message ${message.messageId}');
      }
    
     void firebaseCloudMessaging_Listeners() {
        if (Platform.isIOS) iOS_Permission();
        _firebaseMessaging.getToken().then((token) {
          print(token);
        });
        FirebaseMessaging.onMessage.listen((RemoteMessage message) {
          print(message.notification.body);
    
          RemoteNotification notification = message.notification;
          AndroidNotification android = message.notification?.android;
    
          if (notification != null && android != null) {}
        });
        FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
    
          print('A new onMessageOpenedApp event was published!');
          nextScreen(message, "onLaunch");
        });
        FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
      }
    
    // for IOS permision
     void iOS_Permission() async {
        NotificationSettings settings = await _firebaseMessaging.requestPermission(
            announcement: true,
            carPlay: true,
            criticalAlert: true,
            provisional: false,
            sound: true,
            badge: true,
            alert: true);
    }
    
    // setting up the variables I need
      FirebaseMessaging setUpFirebase(Function next, BuildContext context) {
        _firebaseMessaging = FirebaseMessaging.instance;
        firebaseCloudMessaging_Listeners();
        this.context = context;
        return _firebaseMessaging;
      }
    
      void deleteFirebaseInstance() {
        _firebaseMessaging.deleteToken();
      }
1 Answers
Related