I am trying to send push notifications with an image inside a Firebase Cloud Function using node.js (v10) and a module called 'node-apn'. When I realized I need the APNs key, I reached out to a former dev for it's location. Apparently, it was not to be found so the original APN key was revoked and a new one was generated in Apple Dev console. This APN key was then added to the Firebase Cloud Messaging Settings in the Console.
The iOS app is setup to register device tokens and accept notifications via APNs. My problem is when I send the APN in the javascript cloud function, it results in an error "BadDeviceToken" (400). This happens to all the device tokens stored under my own user doc in Firestore. I realize this is because those tokens are made with the original APNs key, but now that I've added the new one, how do the device tokens get reset?
Here is the node.JS code I am using:
We have a Firestore backend and have the newly created APNs Key properly added to the Firebase Cloud Messaging settings.
The iOS app is setup to register device tokens and accept notifications via APNs. My problem is when I send the APN in the javascript cloud function, it results in an error "BadDeviceToken" (400). This happens to all the device tokens stored under my own user doc in Firestore. I realize this is because those tokens are made with the original APNs key, but now that I've added the new one, how do the device tokens get reset?
Here is the node.JS code I am using:
Code Block language var key = Buffer.from("-----BEGIN PRIVATE KEY-----\nMI9T3g.....jGGUkioo\n-----END PRIVATE KEY-----"); let options = { token: { key: key, keyId: "66X*****", teamId: "*******" }, production: true }; var apnProvider = new apn.Provider(options); var note2 = new apn.Notification(); note2.title = publisher.Username + " posted a new Mag!" note2.mutableContent = true note2.pushType = "alert" note2.payload = { "fcm_options": { "image": publisher.magImage } } return apnProvider.send(note2, deviceTokens).then((response) => { response.sent.forEach(token => { console.log("Notification sent to " + token) }) response.failed.forEach(failure => { if (failure.error) { console.log("Error : " + failure.error.message) } else { console.log("Failure Status : " + failure.status) console.log("Failure response : " + failure.response.reason) console.log("Failure device : " + failure.device) } }) return response }) });
We have a Firestore backend and have the newly created APNs Key properly added to the Firebase Cloud Messaging settings.