How to implement push notification in Swift
Posted By : Manu Gupta | 31-Mar-2015
Creating Certificate from Keychain Access
- Open Keychain access -> Certificate Assisstant -> Request a Certificate from a Certificate Authority.
- Fill your email id and certificate name as shown in picture and after that save the certificate file.
- Go to keys tab and find your certificate and export your certificate as shown in image.
- Next save the private key as pushnotification.p12
Making the App ID and SSL Certificate
- Open developer account with user credentials.
- Create App ID.
- Download Certificate file with aps_development.cer name.
- Create Provisional profile with package name.
- Download Provisional Profile.
Now if you have a server you can just send the export p12 file to the server. and provide device token to server. If you dont have server then generate a PEM file.
Converting files to PEM File
So now we have three files:
- The CSR(Certificate Signing Request)
- The private key as a p12 file (pushnotification.p12)
- The SSL certificate, aps_development.cer
- We need to save these file as they can be used afterwards. After that our first step is to convert .cer file into a .pem file and to do so open the terminal and run the following commands.
openssl x509 -in aps_development.cer -inform der -out pushnotificationCert.pem
- Now we need to convert the private key's .p12 file into a .pem file, execute the below commamds.
openssl pkcs12 -nocerts -out pushnotificationKey.pem -in pushnotification.p12 Enter Import Password: MAC verified OK Enter PEM pass phrase: Verifying - Enter PEM pass phrase:
- Now we need to convert both cert.pem and key.pem file into one .pem file.
cat pushnotificationCert.pem pushnotificationKey.pem > ck.pem
- If you want to check weather your certificate work or now execute the following line:
telnet gateway.sandbox.push.apple.com 2195 Trying 17.172.232.226... Connected to gateway.sandbox.push-apple.com.akadns.net. Escape character is '^]'.
- This will create a reguiler connection to APNS. Now if the above response comes then terminate the command and execute another command.
openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert pushnotificationCert.pem -key pushnotificationKey.pem Enter pass phrase for pushnotificationKey.pem:
THANKS
Request for Proposal
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Manu Gupta
Manu is a Native iOS (Swift) and Titanium lead developer . Manu has good experience working with Swift and Alloy framework as well. He loves watching movies and travelling.