Does firebase set apns-push-type header automatically?
Asked Answered
M

3

19

According to changes in iOS 13 for APNS, silent push notifications require additional header (apns-push-type).

I use Firebase as a mediator between backend and mobile, and I'm wondering if Firebase sets mentioned header automatically when content-available property is set to true.

It is already happening in AWS, as mentioned here.

Can I check somehow in iOS if this header was passed to silent push notification?

I've tested on my devices and everything is working after I updated Firebase dependency to the newest version, even in background. But still I don't have any proof how the header looks like.

Marry answered 25/9, 2019 at 15:4 Comment(2)
Hi @Nominalista, currently fireabase does not provide any documentation regarding iOS 13 update. You can connect their support, I guess they add this header you can check in iOS 13. I will check on my end and update you.Adim
Thanks, please let me know, when you will find out something.Marry
D
6

After digging around a little bit and checking how some open source projects updated their code, here's an example on how to add apns-push-type to Firebase Admin Node:

(I'm using multicast, so your solution might differ.)

const message = {
  priority: 'high',
  sound: 'default',
  notification: {
    title: 'Message Title',
    body: 'Message Body',
  },
  android: { ... },
  apns: {
    headers: {  // Add these 3 lines
      'apns-push-type': 'alert',
    },
    payload: {
      aps: {
        badge: 1,
        sound: 'default',
      },
    },
  },
  tokens: [ ... ],
};

admin.messaging().sendMulticast(message);

I only had a few notifications failing so I haven't been able to fully confirm that the problem is solved yet.

Derickderide answered 8/10, 2019 at 21:43 Comment(0)
V
4

This is what i'm using to send background notificaions to the ios devices. Notice that im setting "contentAvailable" instead of "content-available", everything needs to be a string.

"apns": {
    "headers": {
      "apns-push-type": "background",
      "apns-priority": "5"
    },
    "payload": {
      "aps":{
        "contentAvailable": true
      }
    }
  }

i'm using sendMulticast() method, full example looks something like this:

var message = {
  "tokens": tokensArray,
  "data": {
    "info":"someInfo"
  },
  "apns": {
    "headers": {
      "apns-push-type": "background",
      "apns-priority": "5"
    },
    "payload": {
      "aps":{
        "contentAvailable": true
      }
    }
  }
};

await messaging.sendMulticast(message)
Victorinavictorine answered 9/4, 2020 at 1:35 Comment(0)
A
2

Firebase support responded on my request.

As of today, Firebase does not automatically set the apns-push-type header if content_available is set. One should set it via the header in ApnsConfig. They also recommend to update to the lastest admin SDK version.

I additionally set the apns-priorityheader. Unfortunately all steps didn't solve my problem.

Anticathode answered 26/9, 2019 at 17:47 Comment(1)
Have you tried using underscore? Like apns_push_type? Notice that for Apple accepts content-available property and Firebase accepts content_available in contrast.Marry

© 2022 - 2024 — McMap. All rights reserved.