iOS FirebaseCloudMessaging Notifications not worki

2019-07-27 10:37发布

问题:

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

回答1:

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.