Closed remiroz closed 3 months ago
I am building node.js back-end to send push notifications to Apple Watch.
"apn": "^2.2.0", "node": "20.11.1"
This is how I send notification to watch.
const settings = { apn: { token: { key: "./key.p8", keyId: process.env.APPLE_KEY_ID, teamId: process.env.APPLE_TEAM_ID, }, production: true, }, }; const push = new PushNotifications(settings); const registrationIds = [ "128a2827cf9d3af2c08b435bfc0fb5264fb4d3a80a7f0f2a7fe79ec2769f978d", "fea34620baeeb8bae19147484497a5c6607395e83a36ba8d568ac27f3fd49890", ]; const data = { topic: process.env.APPLE_BUNDLE_ID, body: "Powered by Sender", custom: { sender: "Sender", }, priority: "high", contentAvailable: true, retries: 1, badge: 2, sound: "ping.aiff", alert: { title: "Test Title", body: "Test Body", }, silent: false, truncateAtWordEnd: true, mutableContent: 0, expiry: Math.floor(Date.now() / 1000) + 28 * 86400, timeToLive: 28 * 86400, }; push .send(registrationIds, data) .then((results) => { return res.send({ results }); }) .catch((err) => { res.status(500).json({ err }); });
FYI, the key file is in the right place and the .env file contains all env credentials including Key_id, Team_id and Bundle_id.
I tried to call this endpoint using Postman and got this response.
However, the watch never received a notification even though the it returned a success status to me.
I wonder if there is something wrong with code.
Can anyone help me with this?
Thanks in advance!
I am building node.js back-end to send push notifications to Apple Watch.
"apn": "^2.2.0", "node": "20.11.1"
This is how I send notification to watch.
FYI, the key file is in the right place and the .env file contains all env credentials including Key_id, Team_id and Bundle_id.
I tried to call this endpoint using Postman and got this response.
However, the watch never received a notification even though the it returned a success status to me.
I wonder if there is something wrong with code.
Can anyone help me with this?
Thanks in advance!