【问题标题】:onMessage is not called while data only message on ios在 ios 上仅数据消息时不调用 onMessage
【发布时间】:2019-05-03 08:11:28
【问题描述】:

我正在做 fcm 集成以扑动演示应用程序。当仅数据消息在任何情况下(前景、背景、已杀)(ios 物理设备 iphone5s)通过邮递员发送时,不会调用 onMessage 方法。

我已经尝试过通知+数据消息,它工作正常。如 firebase_messaging 插件中所述。

{
 "to" :"firebase-token",
 "data" : {
     "click_action": "FLUTTER_NOTIFICATION_CLICK",
     "body" : {
        "message":"this is data message"
     },
     "title" : "data title",
     "content_available" : true,
     "priority" : "high"
    }
}

这里是邮递员的通知请求内容

 _firebaseMessaging.configure(
  onMessage: (Map<String, dynamic> message) async {
    Fimber.d("onMessage: $message");
    Fluttertoast.showToast(msg: "onMessage: $message",
      toastLength: Toast.LENGTH_LONG
    );
  },
  onLaunch: (Map<String, dynamic> message) async {
    Fimber.d("onLaunch: $message");
    Fluttertoast.showToast(msg: "onLaunch: $message",
        toastLength: Toast.LENGTH_LONG
    );
  },
  onResume: (Map<String, dynamic> message) async {
    Fimber.d("onResume: $message");
    Fluttertoast.showToast(msg: "onResume: $message",
        toastLength: Toast.LENGTH_LONG
    );
  },
);
_firebaseMessaging.requestNotificationPermissions(
    const IosNotificationSettings(sound: true, badge: true, alert: true));
_firebaseMessaging.onIosSettingsRegistered
    .listen((IosNotificationSettings settings) {
  Fimber.d("Settings registered: $settings");
});
_firebaseMessaging.getToken().then((String token) {
  Fimber.d("token: $token");

});

主页处于初始化状态。
我在 ios 中有权限通知,并且可以很好地使用通知+数据。
-结果应如https://pub.dartlang.org/packages/firebase_messaging#-readme-tab-中所述

【问题讨论】:

  • 你能告诉我们不能正常工作的代码吗?
  • 用代码更新了我的问题......

标签: ios firebase flutter firebase-cloud-messaging


【解决方案1】:

-我从here找到了解决方法
像这样向 json 添加通知和声音

{
 "content_available" : true,
 "priority" : "high",
 "to" :"fcm-token",
 "notification":{
        "sound": ""
 },
 "data" : {
   "click_action": "FLUTTER_NOTIFICATION_CLICK",
   "body" : {
        "message":"3:57pm"
   },
  "title" : "data title",
  "content_available" : true,
  "priority" : "normal"
 }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-13
    • 2012-12-13
    • 2018-11-30
    • 2014-01-12
    • 2021-11-20
    • 2020-12-27
    相关资源
    最近更新 更多