Does device token ever change in Apple Push Notifi

2019-02-11 04:31发布

问题:

I am developing an iOS app in which i have implemented Push Notification. Everything is working fine. But just wish to ask if device Token for my Apple device will ever change??

Also do we need internet connectivity for generating device token.

Thanks

回答1:

device Token for my Apple device will ever change

-- YES. If you restores backup data to a new device or reinstall the operating system, the device token changes. So my suggestion is to update the server with token

do we need internet connectivity for generating device token

-- as far as I know, YES. When you register user, you call method for registration for push notification. This on successful registration call the delegate method -

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken

indicating you are registered successfully for a push notification or on failure it calls -

- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error

indicating failed to register for notification.

You can check it by turning off network and running your application.



回答2:

Based on the Apple Documentation, the answer is YES:

The form of this phase of token trust ensures that only APNs generates the token which it will later honor, and it can assure itself that a token handed to it by a device is the same token that it previously provisioned for that particular device—and only for that device.

If the user restores backup data to a new device or reinstalls the operating system, the device token changes.



回答3:

From the apple docs -

The device token is your key to sending push notifications to your app on a specific device. Device tokens can change, so your app needs to reregister every time it is launched and pass the received token back to your server. If you fail to update the device token, remote notifications might not make their way to the user’s device.

Device tokens always change when the user restores backup data to a new device or computer or reinstalls the operating system. When migrating data to a new device or computer, the user must launch your app once before remote notifications can be delivered to that device.

Never cache a device token; always get the token from the system whenever you need it. If your app previously registered for remote notifications, calling the registerForRemoteNotifications method again does not incur any additional overhead, and iOS returns the existing device token to your app delegate immediately. In addition, iOS calls your delegate method any time the device token changes, not just in response to your app registering or re-registering.

For more APNS Doc