I’m trying to handle silent notification sent to me from by backend which triggers Firebase services and it (probably?) triggers Apple servers to send the push.
I’ve selected Remote notifications and Background fetch in project’s Signing & Capabilities:
The usual notifications tested by Firebase console backend are working fine. Yet, while I want to handle the silent notifications (which I cannot send directly on Firebase console) by implementing the
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void)
method, I got nothing – the method is not called – while backend developer assures me that the silent push notification has been is sent (at least to Firebase).
The piece of code run on the backend to trigger Firebase silent notification looks somehow like this:
ApnsConfig.builder()
.setAps(
Aps.builder()
.setCategory(pushType.toString())
.setContentAvailable(true)
I’m testing it while the app is running – since this silent notification is used to update the state of the app when user triggered something on the web just after he/she interacted with the website (by scanning the website QR code).
To debug it I’m trying to intercept all the connections using Charles application – but for now without any success (I’m not able to see even standard push notification being received – which is being shown). Maybe I should be able to see some logs in the Firebase console which I have not found yet?
How can I prove (or disprove) that the correct notification to the correct device is not being sent and received?
UPDATE:
Using Curl to fire background push is working – while using legacy method of sending the push
curl --location --request POST 'https://fcm.googleapis.com/fcm/send'
--header 'Authorization: key=HERE_AUTH_KEY'
--header 'Content-Type: application/json'
--data-raw '{
"to" : "HERE_FIREBASE_MESSAGING_IDENTIFIER",
"content_available": true,
"apns-priority": 5
}'
2
Answers
As it turned out the problem was with the Firebase platform code - actually I was not receiving background pushes.
On the backend the
putHeader("apns-push-type", "background")
was needed to send correct silent push.Here is a whole code used to send silent push through Firebase platform:
Sadly,
see also here. You should however be able to see if a notification was delivered or not by looking at the result of the sendNotification Method in the backend.
You could use a Websocket to have the server notify the device that something happened and it should update the UI.