发送APN返回BadDeviceToken,DeviceToken格式应该是什么? [英] Sending an APN returns BadDeviceToken, what should DeviceToken format be?

查看:1845
本文介绍了发送APN返回BadDeviceToken,DeviceToken格式应该是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的后端使用带有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 Provider API ,在 APNs Notification API 下提到 -

After hours searching the internet, camp across APNs Provider API, under APNs Notification API it was mentioned that -

对于 device-token 参数,请指定目标设备的设备令牌的十六进制字节。

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

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

Which worked. Device token should be encoded as hexadecimal bytes.

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

这篇关于发送APN返回BadDeviceToken,DeviceToken格式应该是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆