PushSharp returns invalid token for newly created

2019-09-15 12:16发布

问题:

I have had an email from Apple saying that my push notifications certificate is due to expire, so trying to be proactive I have regenerated the certificate and exported the P12 however now when I use that new P12 instead of the old one PushSharp gives me an "Invalid Token" error. If then I use the old P12, the notification is sent successfully.

I have now tried to revoke the old certificate as my theory was that the old certificate was still being used by the application to generate the device's token, however the old P12 still works, the new one doesn't.

Do I have to wait for the old certificate to fully expire before the new one will work?

What other reason could there be for Push Sharp to raise an "Invalid Token" exception?

All this is against a TestFlight (Adhoc) version with the Production ApnsServerEnvironment set for PushSharp.

回答1:

After further investigation, I have found that the P12 export needs to occur against the certificate and not the private key.

I seem to have been mislead by the instructions here https://developer.xamarin.com/guides/ios/application_fundamentals/notifications/remote_notifications_in_ios/

Export the Certificate - Expand the certificate so the associated private key is visible, right-click on the key and chose Export. You will be prompted for a filename and a password for the exported file.