Last updated on July 31st, 2016 at 11:13 am
Apple push notification service (APNS) is widely used to send notification to apple powered device like iPad, iPhone etc.
Apple Push Notification Services (APNS) includes :-
- Custom Text Alerts
- Badges
- Sounds
Implementation of APNS to your application :-
For implementing push notifications in your application , you first need a paid developer account and a iOS Device (Either iPhone or iPad) because push notifications can’t be tested on iOS Simulator.
Step 1 : Create CSR Certificate
- Go to Keychain access in your Mac.
- Click On Certificate Assistant >>>> Request a Certificate from Certificate Authority.
- Enter your details and save it to the disk.
Step 2 : Create p.12 file
- Find the certificate which you`ve created in My Certificates.
- Click on the certificate and expand it . You will see Private Key.
- Select both of them and click on Export.
- Enter your phase password and then your mac password .
- Your p12 file have been created.
Step 3 : Add your app Id in developer`s account
- Open developer.apple.com and login in your account
- Create a new app id and click on configure Push notifications.
- There are two push notification certificates (Development and Distribution). As we want to test the certificates for development , click on development push notification certificate.
- Upload the CSR which you`v created earlier on the upload CSR tab and download your push notification certificate.
Step 4 : Add provisioning profile :
- Create a new development certificate and add your devices in it .
- Download the provisioning profile.
Step 5 : Convert your .p12 file into .pem
For APNS , you need to convert your P12 file (which contains certificate and private key) into .PEM file
- For that , Go the terminal in your mac
- Type cd space location where you`v save p12 file . e.g. cd Saurabh
- Type openssl pkcs12 -in apns-dev-cert.p12 -out apns-dev-cert.pem -nodes -clcerts (where apns-dev-cert.p12 is my p12 file which will get converted into apns-dev-cert.pem )
- It will ask for your phase password which you`v set earlier. Enter that.
- Your .pem file will be created
Upload this file in the php end .
Step 6 : Open Xcode and add apns methods in your AppDelegate.m
That’s all about APNS in iOS applications .
Now at server end i use php to send notification on device you just copy bellow code and replace file name with your file name and add password you set.
Thank you 🙂