菜鸟教程小白 发表于 2022-12-11 17:57:48

ios - 发送APN返回BadDeviceToken,DeviceToken格式应该是什么?


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

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

<pre><code>{&#34;sent&#34;:[],&#34;failed&#34;:[{&#34;device&#34;:&#34;....token....&#34;,&#34;status&#34;:&#34;400&#34;,&#34;response&#34;:{&#34;reason&#34;:&#34;BadDeviceToken&#34;}}]}
</code></pre>

<p>发送到 APN 服务器时的 token 格式应该是什么?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>在网上搜索几个小时后,在 <a href="https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/APNsProviderAPI.html" rel="noreferrer noopener nofollow">APNs Provider API</a> 上露营,在 <code>APNs Notification API</code> 下提到 -</p>

<blockquote>
<p>For the <code>device-token</code> parameter, specify the hexadecimal bytes of the device token for the target device.</p>
</blockquote>

<p>哪个有效。设备 token 应编码为<strong>十六进制字节</strong>。</p>

<pre><code>// Node.js snippet
let deviceToken = Buffer.from(base64Token, &#39;base64&#39;).toString(&#39;hex&#39;);
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 发送APN返回BadDeviceToken,DeviceToken格式应该是什么?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/40303787/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/40303787/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 发送APN返回BadDeviceToken,DeviceToken格式应该是什么?