Can anybody tell me if Firebase supports a mode where the socket connection to FCM is used in the foreground, and a regular (not silent) push notification is used in the background? ie Firebase detects whether the socket connection is active, and directs messages accordingly. I am trying to avoid silent notifications as these won't work in the background if the user has disabled Background App Refresh. Thanks.
Or failing that, is there anyway for a data message with content_available=true (a silent notification) to generate a notification alert when the app is backgrounded. I can't generate this my-self as a local-notification in applicationDidReceiveRemoteNotification: as I am assuming the user has disabled Background App Refresh.
I don't believe this is currently supported. @rsattar probably knows more.
But it sounds like you're trying to get code execution time via notifications even when the user has explicitly disabled background app refresh. What use case are you trying to solve here?
No, I don't want code execution in the background. I would like the reliable socket connection in the foreground for chatting, and a push notification in the background, for less frequent status updates, that works regardless of whether the user has enabled background app refresh / app is terminated, and presents the standard notification alert (basically a bog-standard APNS notification).
If someone sends a chat message to a backgrounded/terminated app, then this would need to be sent as a push-notification. Then hopefully they would open the app and the socket connection would be used for chatting.
At the moment we are sending the apps background/foreground sate to the server and it is using this to decide whether to send a data+notification (non-silent), or data message. It is working ok, although I can see keeping the state synchronised could present some problems.
I was asking can Firebase use its knowledge of the socket connection to do that switching automatically. Or out of interest, is our server able to detect presence (socket connection) via an API call to the Firebase server?
I would like the reliable socket connection in the foreground for chatting, and a push notification in the background, for less frequent status updates, that works regardless of whether the user has enabled background app refresh / app is terminated, and presents the standard notification alert (basically a bog-standard APNS notification).
I might be misunderstanding your request, but if a user disables background app refresh, terminates the app, restarts their device, or enables low power mode, that _only_ affects silent notifications (e.g. content-available: true), and not regular display push notifications (i.e. contains alert, sound, ,badge inside aps).
If you're trying to display a bog-standard push notification when the app is in the background, then sending a regular push notification will be fine.
Yeah, but the complication is the server has to know the state of the device to decide whether to use a data+notification / notification message (background), OR a data message (foreground).
What would be good is if Firebase used its knowledge of the socket connection to make this decision.
I believe it does this with a data message (content_available=true), but switches between socket and silent push notification. Because of some of the complications with silent notifications, what would be good is switching between socket and standard push notification.
From what I have read, a message with a notification component is sent to APNS regardless of the socket state.
This is how I understand things work at the moment:
| |data|data
(content_available=true)|data+notification/
notification|
|---|---|---|---|
|foreground|socket|socket|APNS|
|background|-|APNS
(silent)|APNS|
What I want is a fourth option:
| |data+notification
(socket=true)|
|---|---|
|foreground|socket|
|background|APNS|
I've made up an option here (socket=true). Foreground/Background basically means Firebase socket is connected = true/false.
It could be that I'm seriously misunderstanding how Firebase works or the message options.
Thanks.
Got it. Unfortunately this isn't a feature we plan on adding anytime soon.
I'm going to close this issue as the question was answered and this isn't really a great place for feature requests, but feel free to open a new issue at https://github.com/firebase/firebase-ios-sdk/issues and reference the discussion here.
Most helpful comment
Yeah, but the complication is the server has to know the state of the device to decide whether to use a data+notification / notification message (background), OR a data message (foreground).
What would be good is if Firebase used its knowledge of the socket connection to make this decision.
I believe it does this with a data message (content_available=true), but switches between socket and silent push notification. Because of some of the complications with silent notifications, what would be good is switching between socket and standard push notification.
From what I have read, a message with a notification component is sent to APNS regardless of the socket state.
This is how I understand things work at the moment:
| |data|data
(content_available=true)|data+notification/
notification|
|---|---|---|---|
|foreground|socket|socket|APNS|
|background|-|APNS
(silent)|APNS|
What I want is a fourth option:
| |data+notification
(socket=true)|
|---|---|
|foreground|socket|
|background|APNS|
I've made up an option here (socket=true). Foreground/Background basically means Firebase socket is connected = true/false.
It could be that I'm seriously misunderstanding how Firebase works or the message options.
Thanks.