AndrewBarba / apns2

Node client for connecting to Apple's Push Notification Service using the new HTTP/2 protocol with JSON web tokens

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`UnknownError` when sending `SilentNotification`

rr-codes opened this issue · comments

The error I receive is

{
  "reason": "UnknownError",
  "notification": {
    "_deviceToken": "<OMITTED>",
    "_options": {
      "contentAvailable": true,
      "pushType": "background",
      "priority": 5
    }
  }
}

My code is

    const sn = new SilentNotification(deviceToken)

    try {
        await apnsClient.send(sn)
        res.sendStatus(200);
    } catch (e) {
        const message = `Error sending notification: ${JSON.stringify(e)}`
        console.log(message)
        res.status(500).send(message)
    }

where apnsClient is configured as

export const apnsClient = new APNS({
    team: process.env.APNS_ISS,
    keyId: process.env.APNS_KID,
    signingKey: process.env.APNS_AUTH_KEY,
    host: process.env.APNS_SERVER
})

and process.env.APNS_SERVER is https://api.sandbox.push.apple.com/.

I'm using node v14.10.1.

I think it's the way you defined APNS_SERVER. Try setting it to api.sandbox.push.apple.com. Notice no https or trailing slash

@AndrewBarba Yup, that fixed it; thanks!!