Push Notification in iOS Swift – Create PEM File

The first thing is we have to change the App ID. Go to App Settings -> General and change Bundle Identifier to something unique:

After that, we have to create an App ID in our developer account that has the push notification entitlement enabled. Fortunately, Xcode has a simple way to do this. Go to App Settings -> Capabilities and flip the switch for Push Notifications to On.
After some loading, it should look like this:

Under the hood, this creates the App ID in our member center if it doesn’t exist already, then adds the push notifications entitlement to it. You can log in and verify this:

If any issues occur, manually create the App ID or add the push notifications entitlement in the member center by using the + or Edit buttons.That’s all you need to configure for now.

In your member center, go to Certificates, Identifiers & Profiles -> Identifiers -> App IDs and find the App ID for your app. Under Application Services, Push Notifications should be Configurable:

Click Edit and scroll down to Push Notifications:

In Development SSL Certificate, click Create Certificate… and follow the steps to create a CSR. Once you have your CSR, click continue and Generate your certificate using the CSR. Finally, download the certificate and run it, which should add it to your Keychain, paired with a private key:

Back in the member center, your App ID should now have push notifications enabled for development:

The last thing we need before we close Keychain Access. Right-click on your new push certificate and click on Export:

Save it as PawanProject.p12 to Desktop as a .p12 file:

Before exporting it will ask to enter a password for the p12. You can either leave this blank or enter a password of your choosing. I used “PawanProject” as the password. You’ll then need to enter your log-in password to permit the export.

Next and final thing is we have to create a .PEM extension file most important for sending PUSH NOTIFICATION. iOS Developers give this .pem file to backend developers (A developer that work on server side ). Internally Backend developers use this pem file to communicate with APNS (Apple Push Notification Server). They send message , device token and reference of this pem file to APNS. APNS after receiving these things from our server, authenticates the certificates and send push notification to the that particular device, which backend server have requested with deviceToken. Below are the commands to create pem file.

Three Steps are required to create Pem File

1)CER to PEM ( Intermediate)

In terminal , run the first command to create intermediate .pem file from certificate , which we have downloaded from apple developer account site.

openssl x509 -in aps_development.cer -inform der -out PawanProjectCert.pem

2)Private Key’s PKCS12 to PEM ( Intermediate)

In terminal , run the second command to create intermediate .pem file from the .p12 file, which we have exported from Keychain Access. I have used PawanProject password everywhere. You can use according to your project name.

Here terminal will prompt for export password i.e. PawanProject and again for pass phrase i.e. PawanProject. Pass phrase is a used for security purpose. iOS developer give this pass phrase and .pem ( generated in step 3 ) to the backend team for push notification to work properly.

openssl pkcs12 -nocerts -out PawanProjectKey.pem -in PawanProject.p12

3)Combine CER+KEY to PEM ( Final )

In terminal , run the third command to create final .pem file. This simply combine two .pem files into one final .pem file.

cat PawanProjectCert.pem PawanProjectKey.pem > ck.pem

Things To Remember

Place the aps_development.cer file and PawanProject.p12 file in one folder. Create the pem file in the same folder. Please see the video (on the top of the page.) . All the steps are shown. this process works 100%. If you still have any issues with the .pem file comment me, so that I can help you.

One last thing, do me a favour , if you like this article please share it with your friends.