我正在进行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中有权限通知,并且可以很好地与Notification + data一起使用。
-结果应如https://pub.dartlang.org/packages/firebase_messaging#-readme-tab-中所述

最佳答案

-i已找到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"
 }
}

09-04 12:57