某些类型的 FCM 数据消息未传送到 iOS 台设备

Certain types of FCM data messages are not delivered to iOS device

我有一个发送数据和通知消息的 Cloud Functions 环境。

目前,我正在 iPhone SE (2016) 和 iPhone 7 Plus 上测试 FCM 消息 - 这两个设备之间的行为非常不一致,我想想知道为什么。

以下云功能发送通知和数据消息 - 这两个都已成功传送到两个设备:

// These options are global for all my fcm messages
const options = { priority: "high", timeToLive: 30000, content_available: true }

function sendProfile() { 
    ...
    const fcmToken = ********
    const notif = {
        notification: {
            title: "test title",
            body: "test body"
        }
    }
    admin.messaging().sendToDevice(fcmToken, notif, options);
    const dataMsg = {
        data: {
            id: id,
            type: "match",
            uid: uid,
            name: name,
            age: age.toString(),
            bio: bio,
            img1: String(img1),
            img2: String(img2),
            img3: String(img3),
            pronoun: pronoun,
            error: String(bot)
        }
    }
    return admin.messaging().sendToDevice(fcmToken, dataMsg, options);
}

但是对于以下函数:

  1. 通知消息成功发送到两个设备

  2. 但数据信息只传送到 iPhone SE(而不是 iPhone 7 Plus)

     function sendPlace(fcmToken, placeSnapshot, matchName){
         let docId = placeSnapshot.id;
         let place = placeSnapshot.data();
         console.log("sendPlacee: ", place.name, " to: ", fcmToken);
         const dataMsg = {
             data: {
                 type: "place",
                 name: place.name,
                 latitude: place.l.latitude.toString(),
                 longitude: place.l.longitude.toString(),
                 instruction: String(place.instruction),
                 placeId: docId,
                 picture: String(place.picture1),
                 matchName: matchName,
                 address: place.address
             }
         }
         const notif = {
             notification: {
                 title: "test place function",
                 body: "test the body message"
             }
         }
         admin.messaging().sendToDevice(fcmToken, notif, options)
         return admin.messaging().sendToDevice(fcmToken, dataMsg, options)
     }
    

只有当我删除一些有效负载时,它才会成功发送到 iPhone 7 Plus(我从中删除了 instructionpictureaddress 键值数据负载 - 然后它起作用了)。

知道这里的问题是什么吗?

编辑:我的 Android 设备没有问题。

查看此博客是否可以找到有关 FCM 消息传递的一些信息,以及是否可以找出与 iPhone 7 plus 设备相关的任何问题,您必须在其中减少负载。 https://firebase.googleblog.com/2019/02/life-of-a-message.html

Firebase Cloud Messaging 依靠 Apple 推送通知服务 (APNs) 向 iOS 应用程序发送消息(最大 4KB)。在 iOS、notificationsdata 中,消息的处理方式不同,特别是:

  • 通知消息:FCM 代表客户端应用自动向 end-user 设备显示消息。在这种情况下,应用程序不会生成回调,直到用户点击打开应用程序的通知(在这种情况下, userNotificationCenter(_:didReceive:withCompletionHandler:) 回调被触发)
  • 数据信息: 数据消息由 so-called background notifications 中的 FCM 层转换(“content-available”:true)。后台通知是一种远程通知,不会显示警报、播放声音或标记您应用程序的图标,在这种情况下,客户端应用程序负责处理数据消息。这种通知旨在在后台唤醒您的应用程序,使其有时间从您的服务器开始下载并更新其内容。当发送“data”(background”)通知时,回调application(_:didReceiveRemoteNotification:fetchCompletionHandler:) 在通知到达时触发,并且不会自动触发声音或警报。但是,请考虑 Apple 文档中的这条重要说明:

The system treats background notifications as low priority: you can use them to refresh your app’s content, but the system doesn’t guarantee their delivery. In addition, the system may throttle the delivery of background notifications if the total number becomes excessive. The number of background notifications allowed by the system depends on current conditions, but don’t try to send more than two or three per hour.

因此问题可能与您手机的特定情况有关:通知 消息已正确发送到两部手机,但也许 iPhone 7 Plus os 正在限制或延迟 数据 的接收。