OGeek|极客世界-中国程序员成长平台

标题: ios - 发送APN返回BadDeviceToken,DeviceToken格式应该是什么? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 17:57
标题: ios - 发送APN返回BadDeviceToken,DeviceToken格式应该是什么?

我的后端使用 Node.js 和 Express.js,使用 npm apn 包处理 APN,该包使用 Apple 的新提供者身份验证 token 。 iOS 应用获得许可,将接收到的 32 字节设备 token 发送到后端,编码为 base64 字符串。

但是当尝试使用设备 token (编码为 ascii、utf8 或 base64)发送推送通知时,APN 服务器返回 -

{"sent":[],"failed":[{"device":"....token....","status":"400","response":{"reason":"BadDeviceToken"}}]}

发送到 APN 服务器时的 token 格式应该是什么?



Best Answer-推荐答案


在网上搜索几个小时后,在 APNs Provider API 上露营,在 APNs Notification API 下提到 -

For the device-token parameter, specify the hexadecimal bytes of the device token for the target device.

哪个有效。设备 token 应编码为十六进制字节

// Node.js snippet
let deviceToken = Buffer.from(base64Token, 'base64').toString('hex');

关于ios - 发送APN返回BadDeviceToken,DeviceToken格式应该是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40303787/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4