Does push notification token changes after application update?
Asked Answered
N

2

8

I am asking about two situations:

1) After we do a regular update from the App Store

2) After we simulate an update, by downloading a current version from a Store and installing & running a new version from within Xcode,

does push notification token changes? If changes, how often eg. each time, or from time to time?

I ask this, because I was doing some testing, where I want to preserve Documents folder after an update. So this can be easily done like I described above, by downloading the app from the Store, and running a new version from within Xcode. But, I noticed that push notifications stopped to work. Then I repeated this few times (uninstall the app, install it from the store, then run the upgraded version from Xcode) and every time push notifications worked.

I wonder if this was due to push notification token change?

Nonlinearity answered 25/1, 2017 at 15:33 Comment(4)
When you run a app directly from Xcode on your device the provisioning profile changes. Therefor you will also receive a new token. But yes token could change but don't always change on installing an update.Tallith
@Tallith So basically, if I receive a new token each time I run my Xcode version of an app, I shouldn't be able to receive push notifications, because now, the server sends them to the wrong target (device)? I don't get if this is true, why I am receiving notifications actually after updating using Xcode version of an app?Nonlinearity
No, your provisioning profile changes therefor you are unable to receive push notifications. Since you are probably using a development profile which uses a different APNS server.Tallith
@Tallith It seems that I did some silliness accidentally. What you have said is true, and now (unlike earlier, which was weird, and I don't know how happened, but probably some silliness as I said) I am seeing that everything works like you described.Nonlinearity
E
4

As far as I know,

1) Regular update from the App Store - APNS token doesn't change.

2) It's a bit tricky. And I believe token changes. First I want to let you know the appstore version uses APNS production certificate and the build run from with xcode uses development one. It will generate different token. And if you still send push notification to the apple push production server, you won't get them on your xcode version. You need to send them to the apple push sandbox server.

Errancy answered 25/1, 2017 at 16:4 Comment(5)
Thanks for your response! But how do you explain the fact that sometimes this works, and very rarely doesn't ? If your theory for the second case is correct, that push notifications sent from Xcode version should never come. But they do. Almost all the time...Nonlinearity
I just confirmed that the token changes in the second case.Errancy
Thanks for that info. Does it changes each time for you?Nonlinearity
Yes, each time for me.Errancy
I did more tests and everything worked like you and others have said. I probably did some silliness accidentally.Nonlinearity
I
5

See Apple Docs:

Never cache device tokens; always get them from the system when you need them. Although device tokens are unique to an app and device, they can change over time. The device token can change at any time but is guaranteed to be different when the user restores their device from a backup, when the user installs your app on a new device, and when the user reinstalls the operating system. Fetching the token from the system ensures that you always have the current token needed to communicate with APNs. In addition, if the token has not changed, fetching it is fast and does not incur any significant overhead.

So based on Apple docs there are at least 3 places that it changes:

  • Restore from backup
  • installs on new device
  • reinstalling the OS

So a typical update doesn't change them. I don't ever remembering myself having to agree to receive after an update...

IMPORTANT NOTE:

If a user logs out of the app and a new user logs into the same device, then the token would remain the same. Why? Because there's no class or messaging system exposed to developers to let the OS know it has to deregister a token from device.

Hence you must unregister that token from that user/account, i.e you have to make some sort of network call to your platform, otherwise the new user would be receiving push notifications that belong to the previous user.

Insurer answered 25/1, 2017 at 16:12 Comment(3)
Thanks, but this doesn't really answers my question, especially the second case...Nonlinearity
Also I agree the fact that token should be requested say, on each app launch because it can change (like stated in docs), but I got confused about when it changes when it comes to update, especially in the second case from my question.Nonlinearity
More importantly, what happens to the user topic subscriptions when the device token changes? When I detect a token change, do I have to un-subscribe the users original token from all the topics they were subscribed to and then re-register the user for all the same topics using the new token? Or is this somehow auto-managed in the background - FCM auto removes bad tokens and reassigns new tokens for all the user subscribed topics?Oregano
E
4

As far as I know,

1) Regular update from the App Store - APNS token doesn't change.

2) It's a bit tricky. And I believe token changes. First I want to let you know the appstore version uses APNS production certificate and the build run from with xcode uses development one. It will generate different token. And if you still send push notification to the apple push production server, you won't get them on your xcode version. You need to send them to the apple push sandbox server.

Errancy answered 25/1, 2017 at 16:4 Comment(5)
Thanks for your response! But how do you explain the fact that sometimes this works, and very rarely doesn't ? If your theory for the second case is correct, that push notifications sent from Xcode version should never come. But they do. Almost all the time...Nonlinearity
I just confirmed that the token changes in the second case.Errancy
Thanks for that info. Does it changes each time for you?Nonlinearity
Yes, each time for me.Errancy
I did more tests and everything worked like you and others have said. I probably did some silliness accidentally.Nonlinearity

© 2022 - 2024 — McMap. All rights reserved.