0

Our app is now using the production certificate for iOS push notifications.

We have been through several rounds where pushes work, and then they just stop working. Often the "stop working" is associated with some server failure. However the server we are using says that we are still suing the same p12s generated when I made the certs but they are getting an error code 8 from Apple which means it's an invalide token.

I regenerate the certs and "dirty" the profiles/identifiers reload the p12s on the server and everything works fine ... for a while. Then they just magically start getting "error Code 8"s and we have to start all over again.

Today I noticed that a previous build of our app works fine still but the current build does not. They were both built with the same provisioning profiles and/or enterprise distribution profiles, both were using the same certs for the app ID, both loaded up to TestFlight (just for informational purposes) and have identical push related code in them.

The strange thing is that when I use the older build I get back a 4xxxxx... device token (consistently the same one) and when I use the new build I consistently get back a 5xxxxx... device token from Apple (consistently the same one).

I know for a fact that the previous build was getting the 5xxxx... device token previously because I check that on a fairly consistent basis.

However, I have noticed that some of our testers are registered for more device tokens than they say they have devices so this issue could have been going on for a long time and I mistakenly thought that it was another issue.

What causes the device token to have a consistent but different numbers?

What is the anatomy of a device token?

Does anyone have any idea why the exact same profiles/identifiers would suddenly stop working for the exact same push cert?

Thanks

Eran
  • 387,369
  • 54
  • 702
  • 768
addzo
  • 845
  • 3
  • 13
  • 37

1 Answers1

0

Device Tokens rarely change. The only instances in which I know them to change are when you upgrade your iOS version or restore the device from a backup. Therefore, the fact that you get different tokens for the same device for different builds probably means that one of the builds uses the sandbox certificate and the other uses the production certificate. The only other explanation I can think of is that in order to test the older build you restored your device from backup, thus changing its device token.

From the description of your problem, it seems like your DB contains a mix of sandbox device tokens and production device tokens. They don't mix well. Sandbox tokens are invalid in production environment and vice versa.

You should either clear your DB and start collecting your device tokens from your users, or you should find all the tokens that cause the invalid token response and delete them.

From Apple's Technical Note :

The most common problem is an invalid device token. If the token came from the sandbox environment, such as when you are testing a development build in house, you can't send it to the production push service. Each push environment will issue a different token for the same device or computer. If you do send a device token to the wrong environment, the push service will see that as an invalid token and discard the notification.

Note: It is recommended that you run a separate instance of your provider for each push environment to avoid the problem of sending device tokens to the wrong environment.

Eran
  • 387,369
  • 54
  • 702
  • 768