Flutter - 背景通知在 iOS 中不起作用

Flutter - Background notifications not working in iOS

我正在 Flutter 中创建一个 public 聊天应用程序,但我 无法iOS,当我从我的 Cloud Function 触发方法 admin.messaging().send(payload) 时。

这是我在 Cloud Function 中的负载:

var payload = {
  notification: {
    title: `My Title`,
    body: `My message`,
  },
  android: { priority: "high" },
  apns: {
    payload: {
      aps: {
        contentAvailable: true,
      },
    },
    headers: {
      "apns-push-type": "background",
      "apns-priority": "10",
      "apns-topic": "io.flutter.plugins.firebase.messaging", // bundle identifier
    },
  },
  topic: `mytopic`,
};

我尝试了一堆不同的有效载荷:

我仔细设置了所有我需要的配置,感谢官方文档: https://firebase.flutter.dev/docs/messaging/usage/

我还检查了 Github 个问题,例如这些问题: 1041, 6112, 5988, 1644, 4300, 4097

什么是有效的:

什么不起作用:

我终于解决了这个问题!

我只是删除了负载中的 "apns-push-type": "background" 行。 现在可以使用了。

"apns-topic" 行似乎也没有用。

这是我的最终有效负载:

 var payload = {
    notification: {
      title: `# ${context.params.passion}`,
      body: `${newMsg["senderPseudo"]} ${
        type == "image" ? "a envoyé une image." : `: ${newMsg["message"]}`
      }`,
    },
    // Set Android priority to "high"
    android: {
      priority: "high",
    },
    // Add APNS (Apple) config
    apns: {
      payload: {
        aps: {
          contentAvailable: true,
        },
      },
      headers: {
        //"apns-push-type": "background", // This line prevents background notifications to be displayed
        "apns-priority": "10",
      },
    },
    token: "dnqTQVso60GfnnuOjHv8_e:APA91bElr-K3xkQMdYHX8VMrMZNCYCjO4zJlGseRh25AS_GT7cg9zlOGdQl4KXvr88ypeWjZjrPzrLRHitsQ-JKQK057ZQb_36c_lfsNjHXbYMYI2iS3jV_HGWf7Ene-ZlPvOb0aRr8u"
 };