gpt4 book ai didi

iphone - 请求设备 token

转载 作者:行者123 更新时间:2023-11-28 22:44:24 26 4
gpt4 key购买 nike

在处理推送通知时,didRegisterForRemoteNotificationsWithDeviceToken 会注册设备以接收通知并接收我们之后可以使用的 deviceToken,但是如果在应用程序启动和 didRegisterForRemoteNotificationsWithDeviceToken 运行时没有互联网会怎样?

有没有办法强制 didRegisterForRemoteNotificationsWithDeviceToken 再次运行并接收 token ?

谢谢

最佳答案

您应该阅读此技术说明:TN2265 - Troubleshooting Push Notifications

它说:

When the first push-capable app is installed, iOS or Mac OS X attempts to establish a persistent network connection to the push service that will be shared by all push-capable apps on the system. If neither delegate callback application:didRegisterForRemoteNotificationsWithDeviceToken: nor application:didFailToRegisterForRemoteNotificationsWithError: is called, that means that this connection has not yet been established.

This is not necessarily an error condition. The system may not have Internet connectivity at all because it is out of range of any cell towers or Wi-Fi access points, or it may be in airplane mode. Instead of treating this as an error, your app should continue normally, disabling only that functionality that relies on push notifications.

Keep in mind that network availability can change frequently. Once the persistent connection to the push service succeeds, one of the previously-mentioned application delegate methods will be called.

您应该在每次应用程序启动时调用 registerForRemoteNotificationTypes,即使没有网络连接也是如此。推送框架处理其余部分。在 didRegisterForRemoteNotificationsWithDeviceToken 中,您将 token 发送到您的服务器(如果尚未发送或 token 已更改)。

同时检查 Local and Push Notification Programming Guide :

By requesting the device token and passing it to the provider every time your application launches, you help to ensure that the provider has the current token for the device. If a user restores a backup to a device or computer other than the one that the backup was created for (for example, the user migrates data to a new device or computer), he or she must launch the application at least once for it to receive notifications again. If the user restores backup data to a new device or computer, or reinstalls the operating system, the device token changes. Moreover, never cache a device token and give that to your provider; always get the token from the system whenever you need it. If your application has previously registered, calling registerForRemoteNotificationTypes: results in the operating system passing the device token to the delegate immediately without incurring additional overhead.

关于iphone - 请求设备 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13652071/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com