在iOS上仅发送数据消息时不调用onMessage

时间:2019-05-03 08:11:29

标签: ios firebase flutter firebase-cloud-messaging

我正在进行fcm集成以开发演示应用程序。在任何情况下(背景,背景,被杀死)(邮递员物理设备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中具有权限通知,并且可以很好地与Notification + data配合使用。 -结果应如https://pub.dartlang.org/packages/firebase_messaging#-readme-tab-

中所述

1 个答案:

答案 0 :(得分:0)

-我发现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"
 }
}