【问题标题】:How to get Push-Notification on iOS working with Firebase and Flutter?如何在 iOS 上使用 Firebase 和 Flutter 获得推送通知?
【发布时间】:2019-09-25 09:11:14
【问题描述】:

我尝试了许多不同的教程,例如这个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);
    });
  }

【问题讨论】:

  • 更新:我发现当应用程序在 TestFlight onMessage 时被调用。所以只有当应用程序在前台时。此外,当应用程序在后台并且我发送一条消息(我没有收到推送通知!)但是当我进入应用程序状态时,我写了一条信息消息“在重新启动时被调用”。
  • 看看我的帖子,可能对你有帮助stackoverflow.com/questions/56507900/…
  • @ExtUser1 你解决了后台推送通知的问题吗?

标签: ios firebase flutter firebase-cloud-messaging apple-push-notifications


【解决方案1】:

flutter_local_notifications 的文档说明如下:

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

几个问题:

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

让我知道结果如何:)

【讨论】:

  • 感谢您的回答。我想使用这些软件包,因为当应用程序处于前台时,我可以使用 flutter_local_notifications 弹出消息。我在 Xcode 的后台模式中启用了远程通知。我还创建了证书并在 Firebase 中上传了 APNs Auth Key。我尝试删除 flutter_local_notifications 以测试我是否能够在 iOS 下接收任何消息。我不知道我还能做什么:/
  • 很遗憾,即使没有 flutter_local_notifications,我也没有收到任何推送通知。
  • @ExtUser1 关于这个问题的任何解决方案?
【解决方案2】:

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

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

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

希望对你有帮助

【讨论】:

    猜你喜欢
    • 2017-11-17
    • 1970-01-01
    • 2018-03-11
    • 1970-01-01
    • 2018-06-18
    • 2019-01-30
    • 2019-08-01
    相关资源
    最近更新 更多