AndrewBarba / apns2

Node client for connecting to Apple's Push Notification Service using the new HTTP/2 protocol with JSON web tokens
MIT License
118 stars 32 forks source link

SilentNotification and topic #56

Closed spock123 closed 1 year ago

spock123 commented 1 year ago

When using PassKit, (Apple Wallet), the server sends a silent notifications to those clients that should update their wallet passes.

This is done by sending a Silent Notification. However, this library does not allow for setting the topic when creating a SilentNotification.

PassKit requires the topic to match the passKitType. The issue is that if you have more than 1 passKit type, (example: bookings and membership cards), it's not possible to specify them when creating the SilentNotification.

The only way is to set a default topic when creating the client. But that means that we need to create a new client instance for each type of wallet pass that we support.

It would be really beneficial if SilentNotification would accept a topic to be sent.

Imagine a company with 10 wallet pass type (booking, giftcard etc), they'd be required to create 10 different clients.

Thanks in advance

AndrewBarba commented 1 year ago

@spock123 All set - released in 11.1.0 https://github.com/AndrewBarba/apns2/releases/tag/11.1.0

tjcarrel commented 1 year ago

@spock123 how did you go about using the pass's certificate and key to send the push notification?

AndrewBarba commented 1 year ago

@tjcarrel It sounds like you only need to match the topic to passKitType.

So for example if passKitType = com.example.Acme.PassKit then you could:

import { SilentNotification } from 'apns2'

const notification = new SilentNotification(deviceToken, {
  topic: 'com.example.Acme.PassKit'
})

client.send(notification)
tjcarrel commented 1 year ago

@AndrewBarba appreciate the quick response!

Apple's documentation made it seem like I needed to use the same certificate and private key used to generate the pass. Turns out I can just use a normal APNS2 key along with the code you provided.