Urban Airship device tokens remain active between installs - ios

So I'm running into a peculiar problem that I have not been able to find much information on. Looking for any input or experience at all.
I have recorded the deviceToken of an existing app install using Urban Airship. Then deleting the app and reinstalling, I recorded the new device token as well. These tokens are different. From the UA test panel, I am able to send a test push to both of these tokens and the device receives 2 pushes, one for each token, even though the first token has since been uninstalled. But, in UA device lookup, both tokens are marked as active.
This was only caught after getting our push server running which triggers a push once every morning at most, based on a hosted file that determines the push contents and if one should happen. My development device is now getting up to 8 pushes at once from the server.
There are ways to unsubscribe or unregister for push notifications with Apple, UA, and the server, but I'm wondering on the best practices for this. There is no way to get the uninstall event either which would be the only time to unsubscribe. Is the best solution just to wait for UA to determine a token is inactive? I have found this list here for reasons a token could be inactive: http://docs.urbanairship.com/reference/troubleshooting/ios-push.html#inactive-device-token
But none seem to apply here, especially because some of these device tokens are nearly a month old and still sending to my test device. The app uses an Enterprise profile so this is happening in a production environment.

Are you getting the same channel every time? Usually reinstalls will generate the same channel which is tied to a single device token. Then when apple generates a new token it will update the channel's token. You are probably better off contacting support directly. They will be able to help gather all the device info they need and look up registration and push records to figure out whats going on.

Related

APNS Tokens - Do iOS Sandbox tokens expire?

Just out of curiosity, do sandbox push notifications for iOS expire? The reason I am asking is, yesterday my push notifications were working perfectly for my device and since then I haven't changed the code. Today I wanted to push another notification to further test and all of a sudden, no notification was received. I had to reinstall the app and get another token for it to work.
So, do sandbox tokens expire, or do I possibly have a more serious issue at hand when I go to live?
As of now nowhere it is documented regarding the token expiry. But as an experience and from an architectural point, device tokens will not expire for a smaller duration of time. Because it will create a lot of effort for APNS to generate a new token every time if that is the case. Anyway, you can check your server logs to see the acknowledgement you receive from APNS if it is a failure to deliver a notification.
The device token probably changed from the prior version of the app you were testing. You should check the token each time you launch the app and ensure it's registered because it's likely to periodically change.
https://developer.apple.com/documentation/usernotifications/registering_your_app_with_apns
Never cache device tokens in local storage. APNs issues a new token when the user restores a device from a backup, when the user installs your app on a new device, and when the user reinstalls the operating system. If you ask the system to provide the token each time, you’re guaranteed to get an up-to-date token.

Does push notification token changes after application update?

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?
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 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.

How to check authenticity of iOS device

I have an app-server process that needs to check if the device making a request is an actual iOS device. I used to do this by taking advantage of push notifications. The user first authorizes push. Each time the user makes a specific type of request, I push a code to that device with which the app uses to make a second "authenticated" request to the app server. That additional channel of going through APNS would, in a sense, prove the authenticity of the requester's device. This makes it difficult for a person to spoof the request because they would not be able to receive the push notification with the needed code.
Recently though Apple started enforcing the rule that apps cannot require the user to accept push notifications in order to use the app, even though we do not use push notifications for alerts.
Is there any comparable way for my app server to check with Apple that a request is coming from my app on an actual iOS device? Or is this an unrealistic expectation to be able to determine this.
I could not find the article now, but some guys managed to register raspberry pi as a iOS device and receive push notifications via wifi... that I believe would be concrete proof that not even your first "2 way authentication" is really safe...
Now, directly answering, NO, there's no way for your app server to check if the request did come from a iOS device because all info in a TCP/UDP package is 100% "spoofable"...

iOS- Adhoc Builds with Distribution Certification Push notification comes twice

In my iOS application, I have implemented Push Notification. All working fine except some time push comes twice.
I am using Adhoc Builds with Distribution certificate. In Back-end we send request to APNS only once. Also, we request APNS Production server for any calls
I have googled it but didn't find any solution. Can any one confirm me if this is iOS bug or not.
Also, this is random behavior. As about 80% of time I get two notifications for single event.
Any help would be appreciated
My guess is that you have two different tokens registered for the same device, which causes the server to send the notification twice (one for each token, resulting in two messages being sent to the same device).
Push tokens don't usually change, but they can. This can be a result of re-installing the app, changes in the operating system or any other consideration not fully disclosed to us as the app's developers. That is why Apple indicates that you need to send the most updated version of the token whenever the app is launched.
In your case, it's possible that the token changed for some reason and even though you are sending the notification once for each token, you are sending it once to each of the two tokens representing that device. The explanation for why you're only receiving double messages 80% of the time, is that in the remaining 20%, the messages are sent so close to one another that the operating system (or Apple's servers) are blocking them and only sending one.
Can that be the case?

iOS - Ask for push notification again after updating application

I have a game running in Appstore which connects to one of our development server and now as it is live, I am not able to send push notifications. I need to move it from develpoment server to production server (Urban airship) and it gives me new Api/secret keys. If I update these keys and update my application, will it show alert popup/register to all existing device again to new server? We have around 75k users and I can't afford to loose them! Any idea whats the safest way to play!!
Got it!
The way iOS works, you don't have to worry about the Devices Tokens not registering. Devices will have two Device Tokens per install of an app, a Production Device Token and a Development Device Token, so you should see the new Production Device Token get registered to the app as soon as the user updates and opens the app the next time around. And then you'll be set!

Resources