Post

Replies

Boosts

Views

Activity

APNs key revoked causes “BadDeviceToken” in APN send() result
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: 					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.
1
0
2.5k
Jun ’20