Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 341
James Harpe Avatar asked Mar 21 '14 20:03

James Harpe


People also ask

How do I validate my APNs certificate?

How to Validate the APNS Certificate. A simple command can validate the . pfx file you have taken during the certificate creation/renewal process. This will require the same file and certificate password that was uploaded to the core server.

What is an APNs token?

Apple Push Notification service (APNs) must know the address of a user's device before it can send notifications to that device. This address takes the form of a device token unique to both the device and your app.

How does APN push notification work?

APNS is a cloud-based service that enables apps to send push notifications from a remote server to iOS users through a secure connection. Before iOS users receive your messages, you'll need a p. 12 certificate from Apple, which authorizes push sending through APNS.


2 Answers

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.

like image 128
James Harpe Avatar answered Nov 07 '22 04:11

James Harpe


The device token for production is different than the development one, so if you send a development token to production APNS servers (or vica versa), that's the cause of the problem.

It's possible you didn't remove the development device token from your server when you switched to production.

Or if you are getting the development token from your production app, then either the app is returning a locally stored device token (which you may have stored on your device during development) instead of asking Apple to get a new one, or (if you do ask Apple for a current token and still get the development token) your app is not signed with the production provisioning profile.

like image 23
Eran Avatar answered Nov 07 '22 02:11

Eran