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?
Push tokens can expire when an app is updated, when users transfer their data to a new device, or when they re-install an operating system.
Your push notifications certificates are generally only valid for one year.
App publishers can send them at any time, since users don't have to be in the app or using their devices to receive them. Push notifications look like SMS text messages and mobile alerts, but they only reach users who have installed your app.
A push service receives a network request, validates it and delivers a push message to the appropriate browser. If the browser is offline, the message is queued until the the browser comes online. Each browser can use any push service they want, it's something developers have no control over.
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:
So a typical update doesn't change them. I don't ever remembering myself having to agree to receive after an update...
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 ie you have to make some sort of network call you to your platform, otherwise new user would be receiving push notifications that belong to previous user.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With