56

I am currently testing an app in TestFlight and need a production APNs certificate in order to test Notifications in Firebase.

I have followed all of the steps in this video and successfully configured the development APNs certificate: https://www.youtube.com/watch?v=LBw5tuTvKd4

I've also checked that my steps following the Firebase support guide. Although I note that the Apple Developer site has changed slightly since this guide was written: https://firebase.google.com/docs/cloud-messaging/ios/certs#configure_an_app_id_for_push_notifications

I have generated a production APNs certificate at developer.apple.com using the same method as the development certificate but when I try to upload the .p12 file to Firebase, it gives me the following error:

"The certificate environment did not match. Ensure that you got the right development or production APNS certificate."

I'm definitely uploading a .p12 generated from a production APNS certificate, is there something else I need to do for a production certificate?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Robbie Lewis
  • 2,844
  • 3
  • 18
  • 29
  • I got same error while uploading development.p12 file in production certificate. So, Please check once your p12 is for production or not and then upload it in production. – jayraj m.g. Jun 17 '16 at 06:15

8 Answers8

182

Solved. The mistake I was making was that I was exporting the "private key" part of the certificate in Keychain Access instead of the "certificate" part. As soon as I re exported the .p12 using the correct row in the list - it worked.

Images to illustrate below credit iOS

Don't select & create private key for Production certificate

Correct method:

Directly select certificate & create production certificate

Robbie Lewis
  • 2,844
  • 3
  • 18
  • 29
  • 13
    The doc specifically states to export the key though. – Ben Dubuisson Jun 17 '16 at 04:39
  • 2
    @BenDubuisson I am even convinced I read that you are supposed to export them together and whatnot. But this solved it. Thanks a bunch! – marco Jul 27 '16 at 18:17
  • 3
    In my case I contacted support, they fixed something and I was able to upload it. Again I was exporting the private key which is what you are supposed to do... – Ben Dubuisson Jul 31 '16 at 21:49
  • 4
    Same here, exporting the key like the doc says gave me the same error. But exporting the cert and use that solved it. So or the doc is wrong or something changed. – majodi Sep 05 '16 at 14:34
  • 1
    but you cannot export a p12, without the private key – Peter Lapisu Feb 17 '17 at 20:02
  • 2
    You saved my day! I tried re-creates AppId, Certificate, Provision profile...but didn't worked. Finally, your fix helped me! – Jayprakash Dubey May 16 '17 at 09:58
  • I have added production file into firebase with private key. It's not working. – Jamshed Alam Dec 24 '17 at 08:47
  • 1
    For the development push notification I exported the private key. For production the certificate itself. At least I pointed to the certificate. Maybe there's something I don't get, but finally came to a positive outcome. – gagamil Mar 08 '18 at 06:33
  • 1
    You can't generate a p12 file selecting just the certificate. The right answer is to select *both* the private key and the certificate when exporting to p12. – djanowski May 29 '18 at 17:39
  • Kindly check my answer below @Robbie Lewis – vaibby Sep 18 '18 at 06:16
  • 1
    Google should change their doc where they say expand the certificate .Mistakenly people export private key. It consumed my 2 hours solving this mess – Mujahid Latif Sep 27 '18 at 12:59
  • I cannot see export option without selecting the private key. – Priyal Jan 16 '20 at 18:14
  • didn't work for me. – praveen seela May 02 '22 at 09:05
11

try this

make .csr file and download cert from developer.apple.com

while exporting select private key and certificate both at a same time and export to .p12 with any passphase.

upload tht .p12 file on firebase console.

Thanks

vaibby
  • 1,255
  • 1
  • 9
  • 23
  • This is the right answer, going to suggest it gets incorporated to the accepted answer. Thank you. – djanowski May 29 '18 at 17:37
  • At least for the production cert, this did not work for me. I had to exclude the private key. – Mike M Sep 24 '18 at 14:35
  • it happened with me too. but then It did worked for me both in sandboxing and production. you might have done something differently. I made .p12 of sandbox and production both at a same time with same steps. – vaibby Sep 25 '18 at 15:40
4

Don't select private ket in key chain, directly select certificate and create production certificate.

1) Don't select private ket in key chain.

enter image description here

2) Directly select certificate and create production certificate

enter image description here

Naresh
  • 16,698
  • 6
  • 112
  • 113
2

I am facing the same problem and i have tried all above mentioned solution but nothing works for me than i delete certificate from keychain access and again download certificate and install it than export and try to upload it. It works for me.

0

When I tried the solution suggested here, nothing works (This probably means I am doing right). I solved this issue by replacing Chrome (The application is running for a very long time) with Safari (I invoke the application just for this purpose) for the upload.

That means, if restart Chrome might also work.

FYI.

  • After trying hard to upload the certificate, I eventually click safari for the upload, it works. (Please don't revise my answer since the revision is totally different from my experience.) – Chaohsiung Huang Sep 14 '16 at 02:46
0

In my case I wanted to upload a production certificate to Firebase, and after trying everything I finally realized that I had created a development certificate on iOS Developer...

lorenzo
  • 1,487
  • 1
  • 17
  • 25
0

There might be an inssue of semantics in some cases, so pay attention to meaning.
When you have to upload the certificates in firebase console there are 2 boxes with placeholder text which read:
1. No development APNs certificate
2. No production APNs certificate

In my case, I had understood that I must not upload a development APNs certificate in box 1. Actually, firebase meant that no development Apns certificate has been uploaded yet and that I could upload my certificate.

bibscy
  • 2,598
  • 4
  • 34
  • 82
0

I was having this problem after my previous p12 had expired, I was trying to upload as a new certificate and was getting the “does not match the current environment” error but it uploaded fine once I updated the expired p12 with the new p12 instead of trying to upload the new one alongside the expired one.

wdbwdb1
  • 195
  • 2
  • 9