Zor*_*gan 4 ios firebase google-cloud-functions firebase-cloud-messaging ios14
我有一个发送数据和通知消息的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);
}
Run Code Online (Sandbox Code Playgroud)
但是对于以下功能:
通知消息已成功发送到两个设备
但数据消息仅发送至 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)
}
Run Code Online (Sandbox Code Playgroud)
仅当我删除一些有效负载时,它才能成功发送到 iPhone 7 Plus(我从数据有效负载中删除了instruction,picture和address键值 - 然后它就起作用了)。
知道这里有什么问题吗?
编辑:我的 Android 设备没有问题。
Firebase Cloud Messaging 依赖 Apple 推送通知服务 (APN) 将消息(大小最多 4KB)发送到 iOS 应用程序。在 iOS 中,通知和数据消息的处理方式有所不同,特别是:
\n\n\n系统将后台通知视为低优先级:您可以使用它们来刷新您的应用\xe2\x80\x99s 内容,但系统不\xe2\x80\x99s 保证它们的传递。此外,如果总数过多,系统可能会限制后台通知的传送。系统允许的后台通知数量取决于当前条件,但不要尝试每小时发送超过两到三个。
\n
因此,问题可能与手机的特定条件有关:通知消息已正确传送到两部手机,但 iPhone 7 Plus 操作系统可能会限制或延迟数据消息的接收。
\n| 归档时间: |
|
| 查看次数: |
4310 次 |
| 最近记录: |