2
votes

I have an issue with receiving notifications on Twilio Chat with Production APN Certifications, i get the error:

Error - 52131 Invalid APNs credentials Possible Causes Credential (certificate and private key) is invalid. Certificate expired. Possible Solutions Make sure you have valid certificate and private key provided in your Credential.

When I test my sandbox APN certifcates the push notifications work perfectly.

However when I create APN PUSH SERVICES Certification and upload these and link them to my programmable chat function I get the error message: 52131 - Invalid APNs credentials... https://www.twilio.com/console/runtime/debugger/NOf2857a6c1db54e27984dd8fa9ff5100f

Just to clarify, the push notifications work perfectly on my development project. I use a Sandbox APN certificate, and selected the Sandbox tick box

However in the production version, where I am using:

  • Specific APN Apple Push Services Certificate, for a unique APP ID I get the 52131 error.
  • I did not tick use for sending to Sandbox credential. As it is a push credentiual
  • I followed all the instructions perfectly for exporting the certificate keys.
  • I also use separate API Keys and a separate Programmable chat.
  • I get registration of bindings but no notifications as the certificate is invalid, which I cannot see why as I checked by regenerating a certificate many times

I read in some responses to similar issues having the Sandbox and PUSH SERVICES APN certificate in the same App ID? Or not using the same CertificateSigningRequest to generate the Sandbox and PUSH? Why would this make a difference?

This was the thread: https://github.com/twilio/voice-quickstart-objc/issues/101

1
If your code was working with the sandbox and not with production then this is likeyl not a code issue. I would recommend getting in touch with Twilio support who will be able to help you out. - philnash
As far as I know how to ask them I have github.com/twilio/voice-quickstart-swift/issues/142 and yes I am sure it is an issue with certificates but i want to hear from people who have had similar issues - Ben Smith
Fair enough. I linked to the support team form in my previous comment if that helps at all. Good luck getting it sorted :) - philnash
let me know asap if we have some solution here, since I got the same error. Thank you! - Karoly
@Karoly check my reply below - Ben Smith

1 Answers

4
votes

Finally after several weeks of emailing Twilio support I found the answer.

Basically the issue was probably because I extracted the Keys from my distribution certificate somehow and not the Push one. So make sure you are extracting the correct keys from the correct certification. Also because I was deleting and removing the push credentials from Twilio so often the bindings to my users were pointing to old Push Credentials that did not exist, so I removed the bindings allowing new bindings to be regenerated connecting to the new Push Certificate SID.

Other things that are important for production notifications on twilio programmable chat:

  • Make sure your environment entitlements file is set to "production"
  • Don't check the sandbox option on your production certificate (of course)
  • Sometimes there can be issues when creating a Push Certificate using a certsigningrequest that was used on a sandbox certificate. Try creating a new Cert Signing file just for production
  • When you test your Production notifications these will only work on an appstore build built with your distribution certificate. You cannot receive notifications on the simulator (obviously). You cannot receive notifications from an app built using development certifcate...so you need to build and upload your app to testflight to test the notifications then preferably test between two real devices...or just send notifications from the simulator to a device with an appstore/adhoc build on it

I cannot thing of anything else for now that I came across. Twilio support is very good and will try and answer your question if you need help.