skip to Main Content

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: remote notifications and background fetch setting in xcode project

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


  1. Chosen as BEST ANSWER

    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:

    private fun createSilentApnsConfig(pushType: SilentPushType) =
        ApnsConfig.builder()
            .setAps(
                Aps.builder()
                    .setCategory(pushType.toString())
                    .setContentAvailable(true)
                    .build()
            )
            .putHeader(APNS_PRIORITY, APNS_PRIORITY_FOR_SILENT_PUSH)
            .putHeader(APNS_PUSH_TYPE, APNS_PUSH_TYPE_BACKGROUND)
            .build()
    
    [....]
    
    const val APNS_PRIORITY = "apns-priority"
    const val APNS_PRIORITY_FOR_SILENT_PUSH = "5"
    const val APNS_PUSH_TYPE = "apns-push-type"
    const val APNS_PUSH_TYPE_BACKGROUND = "background"
    

  2. Sadly,

    Apple platforms do not guarantee the delivery of background notifications.

    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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search