Reputation: 9123
I have a Cloud Functions environment that sends data and notification messages.
At the moment, I am testing FCM messages on an iPhone SE (2016) and an iPhone 7 Plus - and the behaviour is very inconsistent between the 2 devices and I'd like to know why.
The following cloud function sends a notification and data message - both of these successfully get delivered to both devices:
// 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);
}
However for the following function:
The notification message successfully gets delivered to both devices
But the data message only gets delivered to the iPhone SE (not the 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)
}
Only when I remove some of the payload, it successfully sends to the iPhone 7 Plus (I removed the instruction
, picture
and address
key values from the data payload - and then it worked).
Any idea what the problem is here?
Edit: There are no problems with my Android devices.
Upvotes: 4
Views: 5140
Reputation: 1772
The Firebase Cloud Messaging relies to the Apple Push Notification service (APNs) to send messages (up to 4KB in size) to the iOS app. In iOS, notifications and data messages are treated differently, in particular:
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.
So the problem could be related to the particular conditions of your phones: notifications messages are correctly delivered to both phones but, maybe, the iPhone 7 Plus os is throttling or delaying the reception of the data ones.
Upvotes: 8
Reputation: 1162
Check this blog if you can find some information on the FCM messaging and if you can figure out any issue relates to iPhone 7 plus device where you had to reduce the payload. https://firebase.googleblog.com/2019/02/life-of-a-message.html
Upvotes: 0