Apple Wallet Pass Series (Part 3): Setting up Updates
Learn how to implement dynamic updates for Apple Wallet passes using Node.js and web services
Apple Wallet Pass Series (Part 3): Setting up Updates
In the previous parts of this series, we navigated the labyrinth of certificate generation and crafted our first digital Apple Wallet pass. Now, it's time to take things a step further by enabling our passes to update dynamically. This means that once a user has added your pass to their wallet, you can push updates to it without any manual intervention from the user. Whether it's updating flight times, changing event details, or tweaking adding points to their loyalty card, dynamic updates enable you to make your passes relevant and useful.
But how do we make this magic happen? Let's dive into the world of web services, push notifications, and a bit of server-side wizardry.
Understanding Pass Updates
Before we get our hands dirty with code, let's understand how pass updates work as its not really an intuitive process.
-
User Installs the Pass: The user adds your pass to their Apple Wallet.
-
Device Registers for Updates: If your apple wallet has a
webServiceURL
, then the device registers itself with your server to receive updates for that pass. This event is triggered when the pass is added to the wallet for the first time. -
Pass Information Changes: Something changes on your end—perhaps a flight is delayed or a special offer is updated, this isn't immediatly reflected on the card, you must inititate the following process.
-
Server Sends Push Notification: Your server sends a push notification to the user's device, indicating that the pass has been updated.
-
Device Fetches Updated Pass: The device receives the notification and contacts your server to fetch the updated pass.
-
Pass is Updated in Wallet: The updated pass replaces the old one in the user's wallet.
In essence, updating passes is a collaborative dance between the device, your server, and Apple's push notification service.
Modifying Pass Generation
To start, we need to modify how we generated our pass in the previous post examine the code below:
In this boarding pass we have the data being added to the pass as the serialNumber and the description. We need to add to the pass on creation a new property called the webServiceURL. This tells the pass what is the base url it should be calling when updating, registering and unregistering the pass. So, a modified version of the above code would look something like this. You may also want to setup the authenticaiton token to prevent your pass being updated by any other malicous servers.
Setting Up the Web Service
To enable pass updates, we'll need to set up a web service at our webServiceURL that handles:
- Registering and Unregistering Devices: Keeping track of which devices have your pass installed.
- Providing Updated Passes: Serving the latest version of the pass when requested.
According to Apple's Wallet Web Service Reference, we'll need to implement the following endpoints:
- Register a Device to Receive Push Notifications:
POST /v1/devices/<deviceLibraryIdentifier>/registrations/<passTypeIdentifier>/<serialNumber>
- Unregister a Device:
DELETE /v1/devices/<deviceLibraryIdentifier>/registrations/<passTypeIdentifier>/<serialNumber>
- Get the Serial Numbers for Passes Associated with a Device:
GET /v1/devices/<deviceLibraryIdentifier>/registrations/<passTypeIdentifier>?passesUpdatedSince=<tag>
- Get the Latest Version of a Pass:
GET /v1/passes/<passTypeIdentifier>/<serialNumber>
Endpoint Implementations
Device Registration
When a user adds your pass to their wallet, their device will attempt to register with your server for updates.
Device Unregistration
When a user removes your pass from their wallet, their device will notify your server to unregister from updates.
Get Updated Passes
When you send a push notification indicating that passes have been updated, devices will call this endpoint to get the serial numbers of the passes that need updating.
Get Latest Pass Version
When a device knows which passes have been updated, it will call this endpoint to fetch the latest version.
Pass Generation Helper
In the /v1/passes/:passTypeIdentifier/:serialNumber
endpoint, we called a function generatePassBuffer(serialNumber)
. Let's implement this function using the passkit-generator
library we used in the previous part.
This is the preamble to allow passes to update at all, but this does not enable us to update them from the servers end. In essence, this allows a pass to update if the user manually updates it but doesn't allow the server to trigger a pass update on the iPhone. To trigger a manual update and test if this is working for you or not go to your apple wallet app on the phone the pass is installed on, then click the pass then the three dots on the top right hand corner, then pass details and on this page that shows the details swipe down and you will see a loader pop up and it should query the above endpoints and update the pass.