node-apn icon indicating copy to clipboard operation
node-apn copied to clipboard

Ay caramba, clarifying the FORMAT of the deviceToken !!

Open smhk opened this issue 1 year ago • 1 comments

From the home page:

apnProvider.send(note, deviceToken).then( (result) => {
});

In iOS:

    func application(_ application: UIApplication,
                                        didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        sendToOurServer( deviceToken.base64EncodedString() )

That string looks like this

gCP1Obmj2HS666szreBiMa5bPT3I/igmjNKdPgKYrKtknA39NTwqMWxQV7YHYwv1plKQcmbgVDQFQofG5WG2lPMRVcdaChR2YCAvKs/f0p0=

In node:

async function sendNotifs() {
	for (const aBase64Token of global.known_apns_tokens) {
		const aTokenData = Buffer.from(aBase64Token, 'base64').toString('hex')
                ...
		apnProvider.send(note, aTokenData).then((result) => {

That string looks like this

8023f539b9a3d86666770b33ade06231ae5b3d3dc8fe28268cd29d3e0298acab649c0dfd356666316c5057b607630bf5a652907266e05434054287c6e561b694f31155c75a0a147660202f2acfdfd29d

Is that in fact correct - the formula is Buffer.from(aBase64Token, 'base64').toString('hex') ...?

assuming you use base64 (ie ".base64EncodedString()") for your communications from iOS devices.

Thank you!

smhk avatar Jul 11 '24 16:07 smhk