3

I have the notifications working in android without any issue, but in iOS I can't figure out what seems to be the problem.

  • I have created the APN file and upload into Firebase iOS Configuration
  • Both Team ID & App ID are correct - double checked
  • The "Push Notifications" is both active in the Apple Developer & Xcode
  • When the App starts a request by iOS is made to allow notifications

I'm using firebase_messaging plugin and in my main.dart I put:

@override
void initState() {
    super.initState();

    if (Platform.isIOS)
      this.fbaseMessaging.requestNotificationPermissions(
            IosNotificationSettings(sound: true, badge: true, alert: true),
      );
}

And when the user logs in I grab the token:

fbaseMessaging.getToken().then((token) {
    // Updates the user account
});

I have tested in Xcode Simulator, in a iOS device in TestFlight as well as in a released version and I never receive any notification and I have no clue how to debug where is the problem.

Followed several tutorials like:

  1. https://medium.com/flutterpub/enabling-firebase-cloud-messaging-push-notifications-with-flutter-39b08f2ed723
  2. https://www.youtube.com/watch?time_continue=450&v=PzjxZsz3Tjk
Linesofcode
  • 5,327
  • 13
  • 62
  • 116

1 Answers1

6

Solved.

All I had to do was changing this:

if (Platform.isIOS)
{
  this.fbaseMessaging.requestNotificationPermissions(
        IosNotificationSettings(sound: true, badge: true, alert: true),
  );
}

To this:

if (Platform.isIOS)
{
  this.fbaseMessaging.configure();
  this.fbaseMessaging.requestNotificationPermissions(
        IosNotificationSettings(sound: true, badge: true, alert: true),
  );
}

Seems like even though I don't use the onResume, onLaunch & onMessage the configure method has to be called.

Linesofcode
  • 5,327
  • 13
  • 62
  • 116
  • 1
    Thanks for this, has struggled with this for 3 days and was redoing the official steps over and over. When I saw your fix I thought, nah this guy must be smoking something, surely this should be in the official documentation, but it worked! A huge thanks! – Robert Benedetto Jul 19 '19 at 02:22
  • @Linesofcode,@Robert Benedetto,anyone help me to resolve this issue.I am not getting notification when app is in background from API.From Firebase Console its working.Can you please send a son format. – Shangari C Aug 09 '19 at 10:31
  • @ShangariC did you resolve it? im facing the same problem – Pablo Johnson Aug 22 '19 at 14:44
  • hello, i have the configure with onmessage and onresume and everything, and the notifications still doesnt work in ios-relase mode but works fine in everything else. – azheen Sep 08 '20 at 18:02
  • @azheen Did you find solution? I am having the exact same issue. Notification works fine in debug but doesn't work in release mode – Sandip Fichadiya Sep 30 '20 at 14:07
  • @azheen I'm facing same issue. how did you fix that? – DNS Jul 14 '21 at 10:37