Apple Push Notification Service - Multiple device tokens are valid for the same device
Asked Answered
Z

4

32

In order for us to send users iOS notifications the following flow occurs: a user installs our app, registers with APNS, and sends the registration token to our server to be used later to send notifications.

The above process is repeated for every device on which the user installs our app; we'd like them to get notifications on all their devices.

In addition to this, the process is repeated when a user uninstalls our app and reinstalls on the same device.

Every time the process repeats we get a new, distinct registration token. This is all well and good however, we noticed that only recently when our app is uninstalled, the device token remains valid after it is reinstalled and a new token is generated. It is our understanding that a single unique token can exist for a device.

Apple's documentation seems to suggest this as well (https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW12)

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.

When a new token is generated after reinstall and sent to our backend, we've got two device tokens that point to the same device and as a result we send multiple notifications to that device. Are we misunderstanding the documentation? If so, what's the typical way of dealing with the reinstall scenario?

Thanks!

Zinnes answered 28/8, 2015 at 16:19 Comment(9)
Did you change your bundle identifier?Embow
I would like to add that I am 100% sure that this is happening, and you are right. This is happening with me as well. I reported this bug to Apple and they closed it saying that it's in beta right now.Duplicature
The same thing is happening to me. devices on ios8 dont do this...but on ios9 it gets different device tokens with each install. It also gives the "____ would like to send you push notifications" alert on each install without changing the date etc. Its definitely hitting the successful delegate callback and I can even send push's to this device....it just changes each install. What to do?Drewdrewett
anybody get proper solution for this?Shifty
I am facing this issue only for my app store app(production app) not for app downloaded from test flight(development app)...I am not able to understand why is that happening?..any solutions for this issue..Decent
Hey friends, How do you fix it ? or any solution for it ? I'm also facing this problem.Bowens
Maybe send the uuid of the device along with the device token to your server. Keep only one device token per device uuid per user in your database.Thimblerig
@GautamJain Have tried if Apple fixed this issue later?Rosenberger
Last I reported this again around 8 months ago and Apple still didn't answer. I'm not sure if it's an issue now @RosenbergerDuplicature
R
11

We just did a test here. On our iOS 8.4.1 test device after reinstalling our app we've received the same token, whereas on iOS 9.1 we always receive a new token after re-installing. This wouldn't be a problem if APNS invalidates the older device tokens, but as far as I can tell it does not. The result is that we're sending duplicate notifications to our users to the same device. Maybe it takes some time to invalidate older token?

We decided to do a server-side fix for this and remove duplicate tokens for one user from our database. Not a good and permanent solution, but a short-term fix for us since our users use the app usually on one device only.

Roberts answered 28/10, 2015 at 23:47 Comment(4)
This is a good solution assuming you only issued APNS tokens to identifiable users in your system. What is the solution if you support sending APNS notifications to anonymous app users?Hiltan
How do you know a token valid?Darien
@CrossleSong if the APNS server doesn't reject the token then it is assumed valid. Also if you send a push to two different tokens and they are both received by the same app then it is apparent that there are two valid tokens for that device.Thread
One solution is to store only one token per user, but that means you can't send to multiple devices.Ruttger
H
2

Yes, I am seeing a single device with the same app (my app), which has been issued different APNS over its short life, many of which are still capable of still receiving a push notification (from production APNS server).

The easy fix would be to just have our backend APNS sending service to only honor the last APNS token received. This is doable, assuming there is another primary key that is unique to every iOS device. Well, since UUID is no longer available, then we have to rely on the Apple Vendor ID. That problem with the Apple Vendor ID is that value can also change over time, so be sure to account for that.

We currently only send push notifications to devices which have our unique member/user ID. This is known to our app, once a user has signed into our app. So, we could use our member/user ID, but if a member/user has multiple devices, that means if we use the last APNS token value as the one that wins, than the same member could NOT have multiple iOS devices receiving push notifications (think iPad and iPhone, pretty common these days).

So, with that being said, when upper-management wants to send push notifications to devices in which no unique member/user has actually signed into, there is a risk of the streams getting crossed.

Hiltan answered 18/11, 2015 at 18:57 Comment(1)
I am getting multiple notifications only for app downloaded from app store not for builds downloaded from test flight...I am not able to figure out main reason causing this issue...Decent
F
1

We have the same problem that we found 2 valid device tokens for 1 device. However, when we tried to verify "uninstalling and reinstalling would generate a new device token, and the former device token is still valid", we got the opposite result. Namely, the new device token was generated, but the former device toke became invalid. I verified this on 3/9/2016 and 3/10/2016.

Not sure if Apple has fixed this bug partially:

a) when the app is uninstalled and reinstalled from now on, the old deviceToken become invalid. (no new issues)

b) currently valid device tokens will continue to be valid. (old issues can't be fixed, the device will still receive multi notificatioins from each valid device token)

Looks like we'll have to use "identifierForVendor" to distinguish a unique device: Cleaning our registration table (and keep the latest deviceToken only) if we see 2 deviceTokens share the same identifierForVendor.

Frisbee answered 10/3, 2016 at 7:35 Comment(3)
I've noticed this only seems to happen to people who have been running both dev + app store builds on their device. Have you had any user complaints or is this something you've only noticed in house?Deguzman
This idea looked promising but according to developer.apple.com/documentation/uikit/uidevice/… says that identifierForVendor "changes when the user deletes all of that vendor’s apps from the device and subsequently reinstalls one or more of them", so unless you have multiple apps installed, it won't solve the problemHarned
vendorIdentifier changes too, but maybe you can generate your own UUID and store it in the keychain (that survives app reinstalls). Use that value as your device id.Ruttger
R
0

"Every time the process repeats we get a new, distinct registration token".

Are you sure about that? 100% sure?

In my experience if you uninstall the app, then re-install it then 99.99% of the time you will get the same device token. If you are getting a new unique device token every single time you uninstall and then reinstall the app then that is something I've never seen in multiple years and multiple apps. Hence maybe something strange is going on.

There are instances when a new device token will get generated but they are rare, are you sure you are not doing something else between uninstallation/re-installation?

P.S. there is a different device token for production builds and release builds, eliminate this factor from your observations - i.e. make sure you're not doing something like installing a prod build, then uninstalling it and re-installing a dev build or vice versa. Even if you are doing this the total number of unique dev tokens would still only be two (though only one is valid per environment).

Roesch answered 28/8, 2015 at 16:40 Comment(5)
It seems to be every time the app is uninstalled and reinstalled it gets a new token. I should have mentioned that it's an ios9 beta device. It could be that apns is generating new tokens for these beta devices only and isn't invalidating the old ones.Zinnes
Apple are going to introduce large device tokens in 2016, but iOS9 is due out in 2015. Maybe its a bug or precursor to large device tokens or due to changes to APN Service that are corresponding with iOS 9.Roesch
i am 100% sure this is happening to me...i can log a different token on each install. It also displays the dialog asking the users permission to allow push notifications....Drewdrewett
are you changing the app bundle id? or the provisioning profiles etc in any way ?Yoakum
I am having the same issue here in 2021Algonquian

© 2022 - 2024 — McMap. All rights reserved.