iOS Question Firebase push, only last message arrives

schimanski

Well-Known Member
Licensed User
I'm using the firebase push to send silent push-messages to my ios-device. This runs very well while the app is in the back-and foreground. Now I have mentioned, that when the device is offline, only the last message arrives, after going online. I didn't mentioned it before, because each message arrives one by one when the device was always online. I didn't set an collapse_key. I tried to set the priority in the data-field to 10, but it did not work. Did I forgot a parameter?

Thanks for help...
 

Erel

Administrator
Staff member
Licensed User
Based on the comments here: http://stackoverflow.com/questions/39886108/adding-collapse-key-in-fcm FCM uses a default collapse_key if you don't explicitly set it. Try to set a different collapse_key to each of the messages.

With that said, you shouldn't expect all the message to arrive. The app should instead pull the data from your server after it received the notification.
 
Upvote 0

schimanski

Well-Known Member
Licensed User
Based on this document

https://firebase.google.com/docs/cloud-messaging/concept-options

I understand it in another way: There is no collapse-key, until it is set one. It seems, that it is only possible to set 4 different collapse-keys for each server.

Non-collapsible and collapsible messages
A non-collapsible message denotes that each individual message is delivered to the device. A non-collapsible message delivers some useful content, as opposed to a "ping" to the mobile app to contact the server to fetch data. Messages are non-collapsible by default except for notification messages, which are always collapsible. FCM does not guarantee the order of delivery.

Some typical use cases of non-collapsible messages are chat messages or critical messages. For example, in an IM app, you would want to deliver every message, because every message has different content.

There is a limit of 100 messages that can be stored without collapsing. If the limit is reached, all stored messages are discarded. When the device is back online, it receives a special message indicating that the limit was reached. The app can then handle the situation properly, typically by requesting a full sync from the app server.

A collapsible message is a message that may be replaced by a new message containing the same collapse key if it has yet to be delivered to the device.

Two common use cases of collapsible messages are send-to-sync messages and . A send-to-sync message is a "ping" that tells a mobile app to sync data from the server. An example would be a sports app that updates users with the latest score. Only the most recent message is relevant.

FCM allows a maximum of four different collapse keys per device to be used by the app server at any given time. In other words, the FCM connection server can simultaneously store four different collapsible send-to-sync messages per device, each with a different collapse key. If you exceed this number, FCM only keeps four collapse keys, with no guarantees about which ones are kept.

Note: On iOS, set content_availablewhen the app server needs to send a Send-to-Sync message. An inactive client app executes your logic in the background, while an app in the foreground passes the message todidReceiveRemoteNotification:.

This is my intention:
Some typical use cases of non-collapsible messages are chat messages or critical messages. For example, in an IM app, you would want to deliver every message, because every message has different content
 
Last edited:
Upvote 0

schimanski

Well-Known Member
Licensed User
I have tried it with different collapse_keys, but I always get only the last message after going online. Is it possible, that when the device is offline, apn sends the notification instead of fcm and apn collapse every erlier messages? Meanwhile I think, that apn is not able to work with non-collapsable messages:eek:

B4X:
Dim sb As StringBuilder
        sb.Initialize
        For Each t As String In Devices
         sb.Append($"'${t}' in topics ||"$)
        Next
        sb.Remove(sb.Length-3, sb.Length)
        Dim m As Map = CreateMap("condition": sb.ToString)
 
        Dim Job As HttpJob
        Job.Initialize("fcm", Me)
 
        Dim data As Map = CreateMap("steuerbefehl": msg.Get("steuerbefehl"), "konferenz": msg.Get("konferenz"), "absender": msg.Get("absender"), "sender": msg.Get("sender"), "filename": msg.Get("filename"), "daten": msg.Get("daten"), "zeitstempel": msg.Get("zeitstempel"), "groesse": msg.Get("groesse"))
        m.Put("data", data)
        m.Put("content_available", True)
        Dim Ck As String =  msg.Get("zeitstempel")
        Log(Ck)
        m.Put("collapse_key", Ck)
        m.Put("priority", 10)
 
        Dim jg As JSONGenerator
        jg.Initialize(m)
        Job.PostString("https://fcm.googleapis.com/fcm/send", jg.ToString)
        Job.GetRequest.SetContentType("application/json;charset=UTF-8")
        Job.GetRequest.SetHeader("Authorization", "key=" & Main.FirebasePushApiKey)

Form here https://docs.tibco.com/pub/business...UID-2ED63B8D-8557-4E10-8348-2D730F5F34B5.html

i got the following info:
GCM supports collapse key out of the box while APNS has no concept of collapse keys. APNS does not require collapse notifications because it stores only a single notification always (which is always the latest) per device. APNS discards the older notifications automatically.

@Erel:
Withthat said, you shouldn't expect all the message to arrive. The app should instead pull the data from your server after it received the notification.

I understand, that it is sometimes a good way to sync the client with the server after each notification. But how is it possible with an instant messenger? Each client has more the 100 contacts and 40 to 50 chats and with a collapsed notify, it is not possible to know, from where messages comes from and the server doesn't know, if a message was delivered. To sync all chats needs a lot of traffic and time.
 
Last edited:
Upvote 0

Erel

Administrator
Staff member
Licensed User
Is it possible, that when the device is offline, apn sends the notification instead of fcm and apn collapse every erlier messages?
Yes, the message is always sent by APN when the app is in the background or not running at all.

i got the following info:
You are correct.

I understand, that it is sometimes a good way to sync the client with the server after each notification. But how is it possible with an instant messenger?
I'm sure that Whatsapp and similar applications do not rely on the message data and connect to the server when the app is opened.
 
Upvote 0
Top