cb_dev
cb_dev

Reputation: 368

IOS wallet pass update automatically using apn and nodejs

I am using apn and nodejs to send notification to users to auto update the pass on the wallet. Passes can be updated with pull to update but i want it to happen automatically. I am using passkit-generator to generate the pass.

Please see code below that i used to send the notification

const pushToken= "99f80ae61eb2beb05b3beb898f35befe8a223ddfa57668f48ef9649e94d9b0ab";
const message = {
    title: "Hello",
    body: "Hello, world!",
};

const options = {
  token: {
    key: require("fs").readFileSync("./authkey/AuthKey.p8"),
    keyId: process.env.KEYID,
    teamId: process.env.TEAMID,
  },
  production: true,
};

const apnProvider = new apn.Provider(options);

const notification = new apn.Notification(
    {
        aps: {
            alert: {
                title: "Hello",
                body: "Hello, world!"
            },
            sound: "default"
        },
        messageFrom: "John Appleseed"
    }
);

notification.topic = process.env.APNS_TOPIC;

notification.alert = message;
notification.payload = { messageFrom: "John Appleseed" };
console.log("notification", notification);
apnProvider.send(notification, token).then((response) => {
  console.log(response;
});

}

I get the response like this

{
"sent": [
{
"device": "99f80ae61eb2beb05b3beb898f35befe8a223ddfa57668f48ef9649e94d9b0ab"
}
],
"failed": []
}

But actually i don't get any notification on the app. Am i doing anything wrong here or can anyone please guide?

Upvotes: 0

Views: 21

Answers (1)

cb_dev
cb_dev

Reputation: 368

Issue Resolved: The problem was with the silent notification sent to devices. Once the Wallet app receives the notification, it automatically sends a request to the endpoint:

v1/devices/:deviceLibraryIdentifier/registrations/:passTypeIdentifier

This endpoint should return a list of serial numbers along with their last updated timestamps. After receiving this response, the Wallet app then makes a request to:

v1/passes/:passTypeIdentifier/:serialNumber

At this point, we return the latest version of the .pkpass file, ensuring the pass is updated seamlessly.

Upvotes: 0

Related Questions