gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 19:30:18 26 4
gpt4 key购买 nike

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

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

  • iPhone SE (2016) 运行 iOS 14 beta 1
  • iPhone 7 Plus 运行 iOS 14 beta 3

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

// 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 设备没有问题。

最佳答案

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

  • 通知消息:FCM 代表客户端应用自动向最终用户设备显示消息。在这种情况下,应用程序不会生成回调,直到用户点击打开应用程序的通知(在这种情况下,userNotificationCenter(_:didReceive:withCompletionHandler:) 回调被触发)
  • 数据信息:数据消息由 FCM 层转换为所谓的 background notifications (“内容可用”:真)。后台通知是一种远程通知,不会显示警报、播放声音或标记您应用程序的图标,在这种情况下,客户端应用程序负责处理数据消息。这种通知旨在在后台唤醒您的应用程序,使其有时间从您的服务器开始下载并更新其内容。当发送“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 操作系统正在限制或延迟接收 em>数据

关于ios - 某些类型的 FCM 数据消息未传送到 iOS 设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63215527/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com