I've upload my app on TestFlight and trying to make voice call using twilio and it's throwing Error - 52134 Invalid APNs device token. I've been reading a lot of tutorials on fixing it but despite all my effort I've been able to fix. In sandbox it worked fine though.
I've done followings:
1) Created a new .certSigningRequest from keychain access
2) Generated new VoIP Services Certificate using above on https://developer.apple.com/account/ios/certificate/distribution/create
3) Added certificate in keychain, Exported .p12 file from keychain
4) Followed instructions on https://github.com/twilio/voice-quickstart-swift to run those three commands to generate key and cert
5) On twilio created a new Push Credential and added Certificate and key by copying and pasting
6) SANDBOX is unticked
7) Change CREDENTIAL SID in my server backend
8) Restarted server
I'm using automatic manage signing so I'm assuming everything should be alright there.
Regarding "APS Environment: production", I'm assuming xCode will make it production automatically when uploaded on TestFlight. I can see that it is included.
Despite all of above I'm still getting this freaking error APS Environment: production
I'm aware that the solution of this problem, in 99% cases, is to regenerate cert but right now I'm stuck. I've tried it two times already.
Not sure what else I can do to fix this issue?
i followed this way. it works for both sandbox and live.
To Create Twilio Certificate. follow this instructions.
STEP 1:
1. An Apple Developer membership to be able to create the certificate.
2. Make sure your App ID has the “Push Notifications” service enabled.
3. Create a corresponding Provisioning Profile for your app ID.
4. Create an Apple VoIP Services Certificate for this app by navigating to Certificates -> Production and clicking the + on the top right to add the new certificate (choose voip cert at the bottom).
5. Download the certificate, export the .p12 from keychain.
STEP 2:
Then follow these steps, by navigating to the folder where you added your .p12.
1. openssl pkcs12 -in liveVoip.p12 -nocerts -out key.pem
2. openssl rsa -in key.pem -out key.pem
3. openssl pkcs12 -in liveVoip.p12 -clcerts -nokeys -out cert.pem
4. openssl pkcs12 -in liveVoip.p12 -out VOIP.pem -nodes -clcerts
in Twillio console, Go to the Push Credentials page and create a new Push Credential. Paste the certificate and private key extracted from your certificate. You must paste the keys in as plaintext:
For the cert.pem you should paste everything from -----BEGIN CERTIFICATE----- to -----END CERTIFICATE-----.
For the key.pem you should paste everything from -----BEGIN RSA PRIVATE KEY----- to -----END RSA PRIVATE KEY-----.
Remember to check the “Sandbox” option. This is important. The VoIP Service Certificate you generated can be used both in production and with Apple's sandbox infrastructure. Checking this box tells Twill to send your pushes to the Apple sandbox infrastructure which is appropriate with your development provisioning profile.
Once the app is ready for store submission, update the plist with “APS Environment: production” and create another Push Credential with the same VoIP Certificate but without checking the sandbox option
STEP 3: To test that your app receives notification, get the device token, open terminal, go to the folder where you added .p12. use this to trigger the voip notification manually.
apn push "<XXXXXX XXXXXX XXXXXX XXXXXX XXXXXX XXXXXX e8aafbd9>" -c VOIP.pem -m "Testing VoIP" -p
NOTE: Sometimes twilio tells invalid apns token. but still we are able to get the voip notification.