2012-11-30 117 views
0

處理推送通知時,didRegisterForRemoteNotificationsWithDeviceToken執行註冊設備以接收通知並接收我們可以在此之後使用的deviceToken的工作,但是如果在應用啓動時沒有互聯網並且didRegisterForRemoteNotificationsWithDeviceToken運行時會發生什麼情況?請求設備令牌

有沒有辦法強制didRegisterForRemoteNotificationsWithDeviceToken再次運行並接收令牌?

感謝

回答

2

你應該閱讀技術說明: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中,將令牌發送到服務器(如果尚未發送或令牌已更改)。

同時檢查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.

+0

確定,但有一個時間增量之間的每個嘗試的iOS做,對不對?如果我現在需要它呢?任何方式來使它現在檢查? – SpaceDog

+0

+1 - 這表明我的公司防火牆由於端口號過高而阻塞了Apple沙箱服務器。謝謝。 – rfsbsb