3

I tried many different tutorials, followed e.g. this one https://medium.com/flutterpub/enabling-firebase-cloud-messaging-push-notifications-with-flutter-39b08f2ed723

But I'm not able to receive any Push-Notifications on my iPhone. It works perfectly on Android.

I use firebase_messaging: ^4.0.0+4 and flutter_local_notifications: ^0.6.1

The problem is that none of the listeners (onMessage, onResume or onLaunch) is getting called in iOS although a token is received with getToken()

There is no error message. I can't find the reason for this behavior. I would be glad if someone could help me out.

Thanks.

_firebaseMessaging.configure(
      onMessage: (Map<String, dynamic> message) async {
        print("IM HERE ON MESSAGE");
        print('on message $message');


        String message_as_String = json.encode(message);
        print(message_as_String);
        String title = "test";
        String body = "test";
        String screen = "test";


        var androidPlatformChannelSpecifics = new AndroidNotificationDetails(
            'your channel id', 'your channel name', 'your channel description',
            playSound: false, importance: Importance.Max, priority: Priority.High);
        var iOSPlatformChannelSpecifics =
        new IOSNotificationDetails(presentSound: false);
        var platformChannelSpecifics = new NotificationDetails(
            androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
        await flutterLocalNotificationsPlugin.show(
          0,
          body,
          title,
          platformChannelSpecifics,
          payload: screen,
        );
      },
      onResume: (Map<String, dynamic> message) async {
        print('on resume $message');
        String screen = message["screen"];

      },
      onLaunch: (Map<String, dynamic> message) async {
        print('on launch $message');
      },
    );
    if (Platform.isIOS) iOS_Permission();
    _firebaseMessaging.getToken().then((token){
      print(token);
    });
  }
ExtUser1
  • 31
  • 1
  • 2
  • UPDATE: I found that when the App is on TestFlight onMessage is called. So only when the App is in foreground. Also, when the App is in background and I send a message (I don't get a push-notification!) but when I enter the App states a info message I wrote "on relaunch was called". – ExtUser1 May 13 '19 at 08:05
  • Take a look at my post, it might help you https://stackoverflow.com/questions/56507900/ios-firebasecloudmessaging-notifications-not-working-in-debug-test-flight-nor – Linesofcode Jun 08 '19 at 20:10
  • @ExtUser1 did you resolve the issue for background push notification? – Shangari C Aug 09 '19 at 10:29

2 Answers2

2

The documentation for flutter_local_notifications states the following:

NOTE: this plugin registers itself as the delegate to handle incoming notifications and actions. This may cause problems if you're using other plugins for push notifications (e.g. firebase_messaging) as they will most likely do the same and it's only possible to register a single delegate.

A few questions:

  • Why do you want to utilise both packages?
  • Have you enabled Remote notifications in Background Modes under your Target in Xcode?
  • Have you created a certificate for notifications on iOS? (APNS: Apple Push Notification Service (link)

Let me know how this turns out for you :)

flarkmarup
  • 5,129
  • 3
  • 24
  • 25
  • Thank you for answering. I want to utilise the packages because I can user flutter_local_notifications to pop up messages when the app is in the foreground. I have enabled Remote notifications in Background Modes in Xcode. I also created the certificates and uploaded the APNs Auth Key in Firebase. I try to remove flutter_local_notifications to test if I'm able to receive any message under iOS. I don't know what I could do else :/ – ExtUser1 May 07 '19 at 19:10
  • 1
    Unfortunately, even without flutter_local_notifications, I don't receive any Push Notification. – ExtUser1 May 08 '19 at 07:14
  • @ExtUser1 Any resolution on this issue ? – Ash Aug 13 '19 at 17:42
0

I know this is quite late, but I had the same issue.

My problem was that I didn't download the 'GoogleService-Info.plist' again after I added the Key to Firebase.

After downloading it again and adding it to the Xcode project, push notifications worked like a charm :)

Hope this helps

Josef Wilhelm
  • 361
  • 1
  • 3
  • 6