【问题标题】:Flutter firebase_messaging iOS app not receiving push-up notifications while app in foregroundFlutter firebase_messaging iOS应用程序在前台应用程序时未收到推送通知
【发布时间】:2019-07-24 05:46:24
【问题描述】:

我正在使用带有“firebase_messaging 4.0.0+1”的颤振。 Android版本运行良好。在 iOS 上,如果应用程序在后台,通知会按预期工作。如果应用程序在前台,则不会调用 onMessage...

_firebaseMessaging.configure(
  onMessage: (Map<String, dynamic> message) {
    print('on message $message');
  },
  onResume: (Map<String, dynamic> message) {
    print('on resume $message');
  },
  onLaunch: (Map<String, dynamic> message) {
    print('on launch $message');
  },
);

_firebaseMessaging.requestNotificationPermissions(
    const IosNotificationSettings(sound: true, badge: true, alert: true));
_firebaseMessaging.getToken().then((token) {
  print('Token: ' + token);
});

【问题讨论】:

  • 对于 iOS,你是在真机上测试吗?
  • 是的,正如我所说,如果应用程序在后台或在 android 堆栈上运行,则通知有效
  • @RSSingh 可以,但我没有使用本地通知插件,只是 firebase_messaging
  • @Kamil 请参考这个链接你可能会发现一些有用的东西github.com/flutter/flutter/issues/18425

标签: firebase push-notification flutter


【解决方案1】:

我在使用稳定的颤振通道时也遇到了类似的问题。在我切换到master之后 flutter channel master 问题已经解决了。

另外值得一提的是,Android 和 iOS 有不同的负载处理程序。

对于有效载荷:

{
    "to": "<token>",
    "notification": {
        "title": "title_test1",
        "body": "body_test_1"
    },
    "data": {
        "id": "123",
        "event": "test_event"
    }
}

data 处理程序将是:

    _firebaseMessaging.configure(
        onMessage: (message) {
          if (Platform.isAndroid) {
             print("Android data handler; id: ${message['data']['id']}; event: ${message['data']['event']}");
          } else if (Platform.isIOS) {
             print("iOS data handler; id: ${message['id']}; event: ${message['event']}");
          }
        },
        onLaunch: (message) {
           ...
        },
        onResume: (message) {
           ...
        },
    );

【讨论】:

    猜你喜欢
    • 2020-12-23
    • 1970-01-01
    • 1970-01-01
    • 2017-05-11
    • 1970-01-01
    • 1970-01-01
    • 2013-01-30
    • 2019-04-04
    相关资源
    最近更新 更多