简体   繁体   中英

How to get Push-Notification on iOS working with Firebase and Flutter?

I tried many different tutorials, followed eg 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);
    });
  }

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 (eg 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 :)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM