James Harpe James Harpe - 1 month ago 24
iOS Question

iOS: Production push notifications, Invalid token from APNS server

My app is now available in the app store, so I've downloaded it to my device. The push notifications were working fine during development. I am using JavaPNS to send out the notifications, and I have switch it to point to Apple's production servers.

However, I'm now getting an Invalid Token error back from the APNS servers.

I have the Archive scheme set to "Release", and I have Release set to use this distribution profile:

enter image description here

Inside that provisioning file, you can see that I have the environment set correctly:

enter image description here

Yet I still get the error. When I look in my database, I think the device token the app is returning to me is the same as the development one, so that could be the problem. But I don't know why it would be returning that, given that the app is signed correctly. This is a device I also used for testing, could that be a problem? Any other ideas about what's happening here?

Thanks!

EDIT: I'm not storing a token in my code, Eran's answer suggests that the only other possibilities are an old token in my database, or the app not being signed by a production profile. I'm cleared my database, so I know it's not the former, and as for the latter, I don't see how that could be the case, since I only have one distribution profile, and as I've shown above, it has the "aps-environment" key set correctly. XCode wouldn't even let me use a development profile for app store submission, would it? A few other possibilities:

Is it possible that something being wrong with key I'm sending with my notifications could cause "Invalid Token"? If so, can I regenerate this key for my existing profiles?

Isn't there another provisioning profile contained in the AppID for the purposes of push notifications? Could a problem with that cause the invalid token error?

Answer

I re-downloaded the push production certificate and exported it from the keychain as .p12. This seems to have solved the problem. It seems strange though that a bad private key was giving me the "Invalid Token" error.