38

Does anyone has an idea about Firebase Cloud Messaging support VOIP pushkit services.

If yes then can someone please do provide guidelines for same.

Same thing which is implemented in Skype / Hangout / WhatsApp or any other VOIP based apps.

Thanks in advance.

Hasya
  • 9,792
  • 4
  • 31
  • 46

4 Answers4

21

At time of writing (FirebaseMessaging 1.1.0/Firebase 3.2.0) FCM uses regular APNs underneath on iOS, so there isn't support for PushKit notifications.

Ian Barber
  • 19,765
  • 3
  • 58
  • 58
  • 5
    As far as I understand, yes, FMC does work with PushKit because, from a server instance, no change is required! It does go through APN. It's the way that's implemented in iOS (different callbacks) that's different from regular push notifications. If you get your identifier through PushKit and feed that into FCM, the service it hits and payload are the same. It just comes to the iOS device, again, through different callbacks. I haven't tested it, but I'm willing to bet it works. I haven't seen any difference in a PHP script that'll push to PushKit vs one that'll do simple Push Notification. – EdGs Oct 07 '16 at 20:01
  • 2
    @EdGs It is more than just different callbacks on the client. The "topic" sent to Apple's server is different for a PushKit notification and the Firebase servers would have to know to send the correct topic. There are now universal push certificates from Apple so you should be able to create a certificate that would support it but unless Firebase sends the correct topic it will be a regular APN and not a PushKit one. – chadbag Jan 19 '18 at 07:56
  • 12
    I just queried Google yesterday about support for VoIP notifications via FCM, and they have informed me it is unsupported and still on their feature request list with no eta. – CoastalB Mar 20 '18 at 11:47
  • 1
    Is it still unsupported? – Opengamer Jul 06 '18 at 10:22
  • 1
    Is it still unsupported ? we are searching on web to use it, but I'm not getting any useful links. – Vasanth Oct 31 '18 at 06:36
  • 1
    Is it still unsupported? – Shubham1164 Feb 13 '19 at 10:31
  • 1
    If there is no code change on the server side, then it must be working. but it is not working. Why??? – Shubham1164 Feb 13 '19 at 10:32
4

This worked for me! Don't forget to add the Authkey_xxxx.p8 file in your directory and don't forget to add .voip to your bundle id in the notification topic.

export const test = functions.https.onRequest((request, response) => {
    const config = {
        production: false, /* change this when in production */
        token: {
        key: "./AuthKey_xxxx.p8",
        keyId: "xxxx",
        teamId: "yyyy"
      } 
    };
    const apnProvider = new apn.Provider(config);
    const notification = new apn.Notification();

    const recepients: string[] = [];
    recepients.push(apn.token('SOME PUSHKIT TOKEN'));
    recepients.push(apn.token('ANOTHER PUSHKIT TOKEN'));

    notification.topic = 'com.your.app.voip'; // you have to add the .voip here!!
    notification.payload = {
        // some payload
    };

    return apnProvider.send(notification, recepients).then((reponse) => {
        console.log(reponse);
        return response.send("finished!");
    });
});
marouan azizi
  • 387
  • 3
  • 5
  • I was missing .voip on the bundle id in the notification topic – Robert Sutton Aug 20 '19 at 03:23
  • Does this mean that the client also needs to subscribe to the topic 'com.your.app.voip' to get the notification? – SleepNot May 26 '20 at 02:15
  • @marouan azizi So with this server code, the app's PKPushRegistry:didReceiveIncomingPushWithPayload() method got called instead of UIApplication:didReceiveRemoteNotification() ? – Gruntcakes Jan 19 '21 at 15:39
  • "failed":[{"status":"400","response":{"reason":"DeviceTokenNotForTopic"} getting this error on adding ".voip" to bundle id – Arjun Jan 28 '22 at 03:38
2

I got PushKit + Firebase working via node-apn. Simply install it via npm to your cloud functions folder. You could get the tokens from your firestore or something like that, but I think that's self-explanatory...

Here is some dummy code:

export const test = functions.https.onRequest((request, response) => {
        const config = {
            production: false, /* change this when in production */
            cert: 'yourCERT.pem',
            key: 'yourKey.pem', 
        };

        const apnProvider = new apn.Provider(config);
        const notification = new apn.Notification();

        const recepients: string[] = [];
        recepients.push(apn.token('SOME PUSHKIT TOKEN'));
        recepients.push(apn.token('ANOTHER PUSHKIT TOKEN'));

        notification.topic = 'com.your.app.voip'; // you have to add the .voip here!!
        notification.payload = {
            // some payload
        };

        return apnProvider.send(notification, recepients).then((reponse) => {
            console.log(reponse);
            return response.send("finished!");
        });
    });

Link to node-apn

  • so with this server code, the app's PKPushRegistry:didReceiveIncomingPushWithPayload() method got called instead of UIApplication:didReceiveRemoteNotification() ? – Gruntcakes Jan 19 '21 at 15:38
  • this behavior is intended, since a pushkit notification has nothing to do with a regular remote notification... If that is what you mean...? – p.wiesinger Mar 01 '21 at 22:49
  • "failed":[{"status":"400","response":{"reason":"DeviceTokenNotForTopic"} getting this error on adding ".voip" to bundle id – Arjun Jan 28 '22 at 03:39
  • Can you please indicate the usage of Firebase in this code? It seems to use just `node-apn` – Anubhab Maji Apr 14 '22 at 16:07
1

Writing in 2022

TL;DR

No, it is not possible at the moment.

Why?

Theoretically, as per apple apns request specifications, it seems like all we need to specify the following in the headers:

apns-push-type: "voip",
apns-topic: "<app-bundle-id>.voip"

and this will send a voip notification via PushKit (of course we have to enable PushKit and Background notification capabilities)

Setting these headers in FCM message can be set possible as per FCM docs like:

{
    "message": {
        "token": "fcm-token",
        "apns": {
            "headers": {
                "apns-push-type": "voip",
                "apns-topic": "<app-bundle-id>.voip"
            },
            "payload": {
                "aps": {
                    "contentAvailable": 1
                },
                "customKey": "customValue"
            }
        }
    }
}

Here FCM sends the message.apns.payload object as it is to the APNs server along with the headers.

But:

Problem comes with certificate and key. Apple does not allow a single key or certificate to have both APNs and VoIP permission scopes and FCM does not allow multiple keys or certificates to be uploaded for the same project.

So, FCM can be used (theoretically) with PushKit but not with APNs at the same time. Although Apple specifies that PushKit uses APNs underneath, but it uses different authentication.

We can either create two different project (very difficult to manage) or use other services for PushKit. I am using serverless architecture but APNs server is not serverless friendly as it needs a persistent connection to be maintained.

Anubhab Maji
  • 520
  • 7
  • 9
  • As far as i see from the description of "Apple Push Notification service SSL (Sandbox & Production)" certificate, it does support both regular and voip pushes: "Establish connectivity between your notification server, the Apple Push Notification service sandbox, and production environments to deliver remote notifications to your app. When utilizing HTTP/2, the same certificate can be used to deliver app notifications, update ClockKit complication data, and alert background VoIP apps of incoming activity." – Kirill Pisarev May 12 '23 at 07:41