问题描述
我的后端使用带有Express.js的Node.js,使用 npm apn
包处理APN,该包使用Apple的新提供程序身份验证令牌。 iOS应用获得了许可,并将收到的32字节设备令牌发送到后端,编码为base64字符串。
My backend uses Node.js with Express.js, handling APN using the npm apn
package, which uses Apple's new Provider Authentication Tokens. The iOS app got permission and sent the received 32 bytes device token received to the backend, encoded as a base64 string.
但是当尝试向设备发送推送通知时令牌(编码为ascii,utf8或base64),APN服务器返回 -
But when trying to send a push notification with the device token (encoded as ascii, utf8 or base64), the APN server returns -
{"sent":[],"failed":[{"device":"....token....","status":"400","response":{"reason":"BadDeviceToken"}}]}
发送到APN服务器时,令牌格式应该是什么?
What should be the token format when sent to APN servers?
推荐答案
在网上搜索数小时后,请浏览,在 APNs Notification API
下提到 -
After hours searching the internet, camp across APNs Provider API, under APNs Notification API
it was mentioned that -
对于 device-token
参数,请指定目标设备的设备令牌的十六进制字节。
哪个有效。设备令牌应编码为十六进制字节。
Which worked. Device token should be encoded as hexadecimal bytes.
// Node.js snippet
let deviceToken = Buffer.from(base64Token, 'base64').toString('hex');
这篇关于发送APN返回BadDeviceToken,DeviceToken格式应该是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!