繁体   English   中英

如何在 iOS 上使用 Firebase 和 Flutter 获取推送通知?

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

我尝试了许多不同的教程,例如这个https://medium.com/flutterpub/enabling-firebase-cloud-messaging-push-notifications-with-flutter-39b08f2ed723

但是我无法在我的 iPhone 上接收任何推送通知。 它在Android上完美运行。

我使用 firebase_messaging: ^4.0.0+4 和 flutter_local_notifications: ^0.6.1

问题是,尽管使用 getToken() 接收到令牌,但在 iOS 中没有调用任何侦听器(onMessage、onResume 或 onLaunch)

没有错误信息。 我找不到这种行为的原因。 如果有人可以帮助我,我会很高兴。

谢谢。

_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);
    });
  }

flutter_local_notifications的文档说明如下:

注意:这个插件将自己注册为代理来处理传入的通知和操作。 如果您使用其他插件进行推送通知(例如 firebase_messaging),这可能会导致问题,因为它们很可能会执行相同的操作,并且只能注册一个委托。

几个问题:

  • 为什么要同时使用这两个软件包?
  • 您是否在 Xcode 的Target下的Background Modes启用了Remote notifications
  • 您是否为 iOS 上的通知创建了证书? (APNS:Apple 推送通知服务( 链接

让我知道结果如何:)

我知道这已经很晚了,但我遇到了同样的问题。

我的问题是在将密钥添加到 Firebase 后,我没有再次下载“GoogleService-Info.plist”。

再次下载并将其添加到 Xcode 项目后,推送通知就像一个魅力:)

希望这可以帮助

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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