'INVALID_TOKEN' When Sending Push Notifications
-
@Paul-Winterhalder Thanks, Paul.
-
Hi Joseph,
Here's a way to test your Push notification setup (outside of brainCloud) to ensure that the cert and token retrieval is configured properly:
- Go to pushtry.com
- Upload the same .p12 file that you're using for brainCloud. Be sure to enter the password too.
- Grab the Device Token(s) that you see in the user's User Summary Page - copy those over, separated by commas
- Production box accordingly (brainCloud always tries to send to Production first, if that fails, sends to Sandbox)
- Enter a test message
- Hit [Send]
We just tried this with one of our test apps and it worked well. Does it work for your setup?
-
Adding in, when we get an error using the device token, we remove it from memory on the brainCloud portal, to prevent spamming the system with bad tokens. So if you look under user Monitoring | User Monitoring | User Summary you won't see the deviceTokens on that profile (due to the error your reporting.)
That said, your registration implementation and device token look fine. I don't think it's an issue with the token.
So perhaps it's an issue with the cert?
On the iCloud dashboard, I would check to ensure the cert used and uploaded with brainCloud had push notifications enabled.
-
@Paul-Winterhalder I'm getting "The credentials supplied to the package were not recognized." No clue what that means, unfortunately.
-
If it is a cert issue. These steps may help: https://www.mobiloud.com/help/knowledge-base/how-to-export-push-notification-certificate-p12/
edit: this link seems to confirm the cert theory. Based on the error message: https://stackoverflow.com/questions/22568648/ios-production-push-notifications-invalid-token-from-apns-server
-
@Joseph-Wiemer My guess would be bad password?
-
@Paul-Winterhalder That's what I thought at first, but no, my password is correct.
-
I agree with Jonathan's suggestion to recreate the P12 file. I'm reading several articles here where someone was getting the same error.
The solution in all cases was to recreate the P12 file.
The quote from the discussion:
I figured out the problem. I revoked and regenerated the certificate again, and this time I only exported the private key (without the certificate). In Keychain access, I exported as .p12 and used the new file and it worked. For some reason, PushSharp wasn't play well with .p12 when both certificate and private key are present in the file.
Here's the link to Stack Overflow:
https://stackoverflow.com/questions/23329040/pushsharp-apns-production-the-credentials-supplied-to-the-package-were-not-recoHope that helps!
Paul.
-
@Paul-Winterhalder That gives me something to pursue. Thanks, Paul!
-
@Paul-Winterhalder I exported just the private key without the cert and pushtry.com now says, "Push notification sent successfully". So, I uploaded this new .p12 file to brainCloud. However, I never actually received a notification on my device, and am still unable to send notifications via the brainCloud dashboard.
-
Okay - the two symptoms:
#1 - You say you never got that push from the pushtry tool. I assume your app wasn't running at the time? Apple hides push notifications from apps if the app is currently running. Try again?
#2 - When you say you can't send notifications, you mean they aren't received - just like #1, correct?
Talking to one of our devs now. He mentions that you need to ensure that the app that's running on the device is built with the correct "entitlements". He's gonna provide more info...
Stay tuned...
Paul.
-
Can you confirm that the cert that you made was for Production? AND! that the apps entitlement was set correctly.
https://developer.apple.com/documentation/bundleresources/entitlements/aps-environment https://developer.apple.com/documentation/usernotifications/registering_your_app_with_apns
By default when building from xcode, the default Push Notification Entitlement is development, ensure this is set to production.
Have you confirmed you received the Push notification from pushtry.com on your device ?
-
And note, if you change the entitlement, after rebuilding, you'll need to re-run the app on your device - which I believe will cause it to register a new, updated device token... You'll want to use that one for your tests...
Do I have that right Steve?
-
Correct! @Paul-Winterhalder Keep us updated @Joseph-Wiemer
-
#1 - My app was not running at the time, and I tried again.
#2 - That's correct. And I'm still getting the same INVALID_TOKEN error in "Recent Errors".My app does have the correct "production" entitlement, yes.
-
@Steve-Jones Yes to both. My cert is for distribution and my app entitlement is set to "production". No, the notification from pushtry.com never appeared on my device, despite the service claiming to have been successful.
-
Dumb question - do you have any other devices that you can load your app on and try with? It's certainly suspicious that pushtry isn't working for you.
At this point I'd be removing the app from the device, re-installing, re-running (to register what I believe would be a new device token), and retrying the send - both from pushtry and brainCloud.
If both pushtry and brainCloud don't work - the common denominators are your app's configuration, the device itself, and Apple's servers...
-
@Paul-Winterhalder Yes, I do have other devices I could try. I realize this probably isn't a brainCloud problem, so I appreciate all the help you guys have given me, here. Thank you, and I'll keep trying to figure it out.
-
@Joseph-Wiemer No worries - good luck! And keep us posted!
-
Ok guys, I've solved it! It was some godforsaken problem with my .p12 file.
- Tried creating a .p12 file by exporting both the private key and the cert. FAILED.
- Tried creating a .p12 file by exporting just the private key. FAILED.
- Tried creating a .p12 file by exporting just the cert. SUCCESS.
So, notifications are now working for me. Not sure how to mark this question as solved, but it's solved. Thanks for all your help!