获得 APNs 响应 BadDeviceToken 或 Unregistered 的可能原因是什么? [英] What are the possible reasons to get APNs responses BadDeviceToken or Unregistered?

查看:102
本文介绍了获得 APNs 响应 BadDeviceToken 或 Unregistered 的可能原因是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

向 iOS 用户发送通知时,对于其中一些用户,我收到响应状态代码 400(BadDeviceToken)或代码 410(未注册).

来自关于BadDeviceToken"的 Apple 文档:

<块引用>

指定的设备令牌不正确.验证请求是否包含有效令牌并且令牌与环境匹配.

坏"是什么意思?我知道设备令牌在更早的时间是有效的.用户如何做才能使其设备令牌变坏?

来自关于未注册"的文档:

<块引用>

指定主题的设备令牌无效.

这是否必然意味着该应用已被删除?或者,此响应可能有其他一些原因.

解决方案

正如您引用的

接下来,生成存档后,打开管理器(通过 Window 菜单 > Organizer),选择存档,然后单击 Export... 在右边.您应该会看到四种分发方法:

如果您选择 App Store 或 Enterprise,您将在后面的对话框中看到 Xcode 将 APNS 授权更改为生产(参见红色箭头的提示):

如果您选择 Ad Hoc 或 Development,aps-environment 下的文本将是 development,然后应匹配后端的配置.

When sending notifications to iOS users, for some of them I get response status code 400 (BadDeviceToken) or code 410 (Unregistered).

From Apple documentation about "BadDeviceToken":

The specified device token was bad. Verify that the request contains a valid token and that the token matches the environment.

What is the meaning of "bad"? I know for a fact that the device token was valid at some earlier time. What does a user do to make its device token bad?

From documentation about "Unregistered":

The device token is inactive for the specified topic.

Does this necceserally mean that the app has been deleted? Or there can be some other reasons for this response.

解决方案

As you've quoted from Table 8-6 in the APNS documentation, there are two possible causes for the error:

  1. That the device token is invalid
  2. That the device token does not match the environment

If it is the first case, make sure that the iOS app registers the device for remote notifications every single time that the app is launched because there are many reasons for the device token to change across launches, as outlined in Configuring Remote Notification Support.

If it is the second case, you need to be sure that:

  • The backend uses development configurations if your app build was signed with development APNS entitlements, and
  • The backend uses production configurations if your app build was signed with production APNS entitlements.

Luckily, as the iOS developer, you don't need to directly change the APNS entitlements yourself. It is always in development, and is only automatically changed by Xcode to production when you generate the build and export for App Store or enterprise distribution. As for the backend, your backend developer should know how to configure the backend for development and production environments. For some frameworks, it is a matter of toggling some boolean named isProduction. Ultimately, according to Communicating with APNs under the section APNs Connections, push notifications are sent to different APNS endpoints depending on whether the environment is production or development.

Let's pretend that the BadDeviceToken error is due to the second case--that the device token registered by the app does not match the backend's properly configured development environment. First, in your Xcode project, check your .entitlements file and verify that the APS Environment key's value is development. It should look like this:

Next, after you generate an archive, open the Organizer (via the Window menu > Organizer), select the archive, and click on Export... at the right. You should see four methods of distribution:

If you select App Store or Enterprise, you will see in the later dialogs that Xcode changes the APNS entitlements to production (see tip of red arrow):

If you select Ad Hoc or Development, the text under aps-environment will be development, which should then match the backend's configurations.

这篇关于获得 APNs 响应 BadDeviceToken 或 Unregistered 的可能原因是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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