Flutter IOS FCM push notification not coming into notification bar
Asked Answered
L

5

3

I am new to Flutter and IOS. I am configuring FCM push notifications for both Android and IOS.For android its working fine.I have done by referring this link https://medium.com/@jun.chenying/flutter-tutorial-part3-push-notification-with-firebase-cloud-messaging-fcm-2fbdd84d3a5e . For IOS, if the app is opened and if I send FCM from Firebase Console at the same time , Flutter on message is called (See the screenshot , logs are there) . But if I close the app , notification is not coming to notification bar but I am receiving in Android App, I don't know where is the problem , Problem with Apple Profiles or Flutter .

IOS Build Settings and Signing & Capabilities

IOS build Settings

Here is my code in flutter,

    class FirebaseNotifications {
       FirebaseMessaging _firebaseMessaging;
       SharedPreferences _sharedPreferences;

       void setUpFirebase() {
         _firebaseMessaging = FirebaseMessaging();
         initializeSharedPreferences();
         firebaseCloudMessaging_Listeners();
        }

        void initializeSharedPreferences() async {
        _sharedPreferences = await SharedPreferences.getInstance();
        }

        void firebaseCloudMessaging_Listeners() {
        if (Platform.isIOS) iOS_Permission();
        _firebaseMessaging.getToken().then((token) {
        _sharedPreferences.setString(Preferences.device_token, token);
         print('Token'+token);
         });

         _firebaseMessaging.configure(
          onMessage: (Map<String, dynamic> message) async {
          print('on message $message');
         },
          onResume: (Map<String, dynamic> message) async {
          print('on resume $message');
         },
         onLaunch: (Map<String, dynamic> message) async {
         print('on launch $message');
         },
       );
     }

     void iOS_Permission() {
     _firebaseMessaging.requestNotificationPermissions(
     IosNotificationSettings(sound: true, badge: true, alert: true));
     _firebaseMessaging.onIosSettingsRegistered
     .listen((IosNotificationSettings settings) {
     print("Settings registered: $settings");
    });
   }
  }
Liquorice answered 3/3, 2020 at 8:54 Comment(0)
F
4

In case anyone else runs into this in the future, to expand on this answer. The issue was that in the Info.plist FirebaseAppDelegateProxyEnabled was set to bool rather than a string so:

    <key>FirebaseAppDelegateProxyEnabled</key>
    </false>

becomes

    <key>FirebaseAppDelegateProxyEnabled</key>
    <string>0</string>
Forgiving answered 17/7, 2020 at 11:44 Comment(2)
You saved my life ! I add to migrate from classic notification to silent push notification using Notifee. Can't make it works ... Until I disable FirebaseAppDelegateProxyEnabled with string value ... You also have to implement didRegisterForRemoteNotificationsWithDeviceToken and didReceiveRemoteNotification to make it works and don't forget the content-available inside your apns payload !Righteous
Thanks a lot ... I was hitting my head on the roof :)Frontolysis
P
1

it's weird that it says Push Notifications (Profile) in your Xcode Capabilities Tab.

Maybe remove it again and add it again. And did you check the boxes "Background fetch" and "Remote notifications" in the "Background Modes"

enter image description here

Peel answered 24/4, 2020 at 12:41 Comment(0)
E
1

You are not alone in this problem - try this solution.

Also, check if it not working both on debug and release builds of the application - there is a possibility of notifications not parsed by the debug variant of app.

Eolian answered 31/5, 2020 at 15:7 Comment(1)
Links to external resources are encouraged, but please add context around the link so your fellow users will have some idea what it is and why it’s there. Always quote the most relevant part of an important link, in case the target site is unreachable or goes permanently offline. Please also check How to AnswerAfricander
G
1

I managed to fix the problem with this solution:

  1. In your info.plist:

     FirebaseAppDelegateProxyEnabled: false
    
  2. Add this to your AppDelegate:

    override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    
       Messaging.messaging().apnsToken = deviceToken
       super.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)
     }
    
Gooding answered 20/7, 2020 at 18:55 Comment(1)
Quote your answer with the references when you're just copying it.Drusilladrusus
V
1

Make this replacement in your info.plist file .

Replace <false/> by <string>0</string>

Before :

enter image description here

Now :

enter image description here

Info : If you don't have this code in your info.plist and you don't receive the notification as well, make sure you add it.

Don't forget , here is the new code :

<key>FirebaseAppDelegateProxyEnabled</key>
<string>0</string>

Hope that it will be useful

Verbify answered 8/2, 2021 at 14:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.