Is the APNS device token ever changed?

Once created, does the push notification device token ever change?

Example when the application is updated? or in any other case it may change

+90
objective-c apple-push-notifications
Jul 11 '11 at 15:06
source share
13 answers

From [Apple Documentation ApplePushService] 2

The form of this trust phase of the token ensures that only the APN generates the token that it will subsequently use, and he can verify that the token transferred to him by the device is the same token that was previously provided for this particular device, and only for this device .

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

+67
Jul 11 '11 at 16:16
source share
— -

Apple's official documentation is still unclear. I observed this: the token is invariant for a given device, application, and domain (production vs. sandboxing). I believe that this should remain true in order for the system to work reliably. Consider a situation where an application update launches a new APN token; if I used the largest new app like Twitter with notifications turned on, what happens when I update the app from iTunes? Should I expect it to continue to send notifications, even though I did not start the application, since I am “synchronizing” the update with me on the device? The act of changing the application cannot affect the APN system, since the OS can receive notifications on your behalf, even if you did not run the updated application.

To be clear, Apple states: "The application must register [with APN servers] every time it starts and provide its provider with the current token." I totally agree; this will protect your application from bad assumptions or unusual situations.

One of the answers to: Are notification notification tokens unique in all applications for a single device? indicates that device tokens are unique to “install an operating system”; and that restoring from the backup to the device will support the token, but cleaning the device will result in a new token. This would be fully consistent with Apple’s intent to ensure smooth operation and confidentiality: wiping the device is serious enough that it may require a new association, but the user restoring the image after updating the OS will want to keep his existing notifications. If I recall the recent iOS5 update on my iPad, I restored the most recent backup after the update, so that this would ensure consistent notification tokens. [Edit: restoring the backup to another device will not duplicate the token.]

nuance: I do not have final knowledge on this issue, only some reasonable experience working with APN (as a third-party developer). As always, it's best to check your assumptions.




Update (June 2012):

Recently, I had the opportunity to talk with Apple engineers and b> run some real tests, and I wanted to present the results:

To be complete, when I talk about returning an APN token, I assume the context of a single package identifier / application.

First, Apple engineers said it should not be possible for two devices to return the same APN. Despite the comments below, I could not determine the circumstances when this fails.

Secondly, here is a test update sequence and results:

  • Start with iOS4 installed on iPhone4; backup device in iTunes

  • Upgrade to iOS5
    From the previous test, I know that the APN token is now different

  • Restore device backup APN current now matches step 1.

  • Reset iOS (clean device)
    APN token changes

  • Backing up another phone to iTunes and restoring this backup to test the device; basically, I restore the “wrong” backup, as if I switched phones.
    The APN icon changes again; further it differs and does not correspond to the tokens or the original token or the “cloned” token.

  • Restore the “correct” backup of the device.
    APN current now matches step 1.

  • Finally, I upgraded the phone to iOS6 (beta2), restored my backup, and retested. As expected, the token continued to match the token in step 1.

At this point, I am sure that APN tokens cannot be duplicated between different devices; it may have happened as an error in earlier versions of iOS, but I’m sure that iOS5 (and, presumably, iOS6) process APN tokens correctly.




Update (August 2012)

I just realized that I did not add this: device tokens will change. One of the Apple developers shared with me that the tokens really expire (in two years, I think). For many purposes, this is long enough, which can be considered invariant.

[I'm not worried if I need to update my test scripts with new tokens every two years, especially since I change phones every year.]

+135
Nov 03 '11 at 17:57
source share

I just tested it with changes in iOS9 and APN tokens if I reinstall the application.

+44
Nov 30 '15 at 20:26
source share

YES , device tokens are subject to change.

At any time when your application receives a token, it must store it. Then, whenever a new token is accepted (which will happen in the end), compare the new token with the stored token and if they differ:

  • Update your device local storage (including possibly nil )
  • Update something on a device using a token to find out about a new token
  • Update any APIs that know this token to a new token.

As a practical matter, the last step is likely to be non-trivial. For example, if you have a service that sends weather alerts to a device token based on what zip code the device is subscribed to, you need to pass old_token and new_token to the specified service so that it can update delivery.

Ergo, generally speaking, 100% of the APIs accepting the “device token” must also have some kind of UPDATE object for this token. In order not to build for this, you need to build for incorrectly delivered and not delivered notifications.

+21
Nov 23 '13 at 19:50
source share

The device token is changing from iOS 8 and later.

Please see the text below from the Apple website. Register, schedule, and process custom notifications

A device token is your key to send push notifications to your application on a specific device. Device tokens can change, so each time you start the application, you must re-register it and transfer the received token back to the server. If you fail to update the device token, deleted notifications may not reach the user device. Device tokens always change when the user restores backup data to a new device or computer or reinstalls the operating system. When transferring data to a new device or computer, the user must run your application once before remote notifications are delivered to it.

+7
Feb 18 '16 at 17:55
source share

It should not change if your application is not restored to the new device (after which it will not be asked to accept push notifications again and just send you a registered call, at this point you must accept the new token).

But Apple does not guarantee that it will never change (therefore, the documentation never mentions this). Better program for the worst and suggest that it might change one day. In addition, sending a token to your server regularly allows you to remove tokens that have not yet been registered, and may have uninstalled your application or lost interest some time ago (and the documentation states this as the desired behavior!).

+3
Jul 11 '11 at 15:33
source share

Links quickly become obsolete with an apple! therefore, I quote what now seems perfectly clear:

Never cache device tokens in your application; instead, remove them from the system when you need them. APN will issue a new device token for your application when certain events occur. The device token will be guaranteed to differ, for example, when the user restores the device from the backup, when the user installs your application on a new device and when the user reinstalls the operating system. Retrieving the token, rather than relying on the cache, ensures that you have the current device token necessary for your provider to communicate with APN. When you try to extract a device token, but it has not changed, the fetch method returns quickly.

From this guide

+2
Jul 10 '17 at 8:28
source share

APNs can issue a new device token for a number of reasons:

  • User installs your application on a new device

  • User restores device from backup

  • User reinstalls operating system

  • Other system events

As a result, applications must request a device token at startup.

Contact - Apple Docs

Note: APN device tokens are of variable length. Do not hardcode their size.

+1
Apr 19 '18 at 6:34
source share

I think it's worth mentioning since no one has done this so that the token changes after you unregisterForRemoteNotifications . The next time you call registerForRemoteNotifications token will be different. I could not find confirmation of this in the Apple documentation, but I myself witnessed this behavior. Please keep this in mind.

+1
Dec 12 '18 at 15:32
source share

As a reference to Apple push notification stuff

A device token is your key to send push notifications to your application on a specific device. Device identifiers can change, so your application must re-register at each start and transfer the received token back to your server. If you were unable to update the device token, remote notifications may not reach the user device. Token devices always change when the user restores backup data to a new device or computer or reinstalls the operating system. When transferring data to a new device or computer, the user must run the application once before remote notifications can be delivered to this device.

Never cache a device token; Always get a token from the system when you need it. If your application, previously registered for remote notifications, again calls the registerForRemoteNotifications method, there is no additional overhead, and iOS immediately returns the existing device token to the application delegate. In addition, iOS calls your delegation method at any time when the device’s token changes, and not just in response to registering or re-registering your application.

0
Aug 11 '16 at 7:30
source share

According to this link device token

The device token included in each request is the identifier of the device receiving the notification. APN uses device tokens to identify each unique application and device combination. It also uses them to authenticate the routing of remote notifications sent to the device. Each time your application runs on the device, it extracts this token from the APN and sends it to your provider. Your provider stores the token and uses it when sending notifications to this particular application and device. The token itself is opaque and stable, it changes only when the data and device settings are erased. Only APNs can decode and read the device token.

0
Dec 14 '16 at 9:54 on
source share

Yes, he can change. Ideally, when we get the token through the callback method

  • (void) application: (UIApplication * application) didRegisterForRemoteNotificationsWithDeviceToken: (NSData *) deviceToken

The application must register / update the token on the remote server. This will ensure token synchronization on APNS and your server.

According to Apple Documentation

The receipt and processing of the token of the device intended for the application works as follows:

Your application is registered using APN for remote notifications. When a new device token is needed, the APN generates one using the information contained in the device certificate. It encrypts the token using the token key and returns it to the device, as shown in the middle, right arrow. The system delivers the device token back to your application by calling application: didRegisterForRemoteNotificationsWithDeviceToken: delegate method. After receiving the token, your application (as part of the delegate method) should send it to your provider in either binary or hexadecimal format. Your provider cannot send notifications without this token. For more information, see Registration for Remote Notifications in Configuring Remote Notification Support.

0
Apr 04 '17 at 10:05 on
source share

Device token relay when installing the application.

This means that if you reinstall the application, it will change ; this does not mean if you make it from a backup, iOS upgrade ecc ..

The correct way to use it to avoid any problems is to get the value specified in NSPAppDelegate every time the application starts, in the didRegisterForRemoteNotificationsWithDeviceToken method

0
Jul 11 '17 at 14:58
source share



All Articles