Apple push notification service (APNS) is widely used to send notification to apple powered device like iPad, iPhone etc.

APNS apple

Apple Push Notification Services (APNS) includes :-

  1. Custom Text Alerts
  2. Badges
  3. 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

  1. Go to Keychain access in your Mac.
  2. Click On Certificate Assistant  >>>> Request a Certificate from Certificate Authority.
  3. Enter your details and save it to the disk.

Step 2 : Create p.12 file 

  1. Find the certificate which you`ve  created in My Certificates.
  2. Click on the certificate and expand it .  You will see Private Key.
  3. Select both of them and click on Export.
  4. Enter your phase password and then your mac password .
  5. Your p12 file have been created.

Step 3 : Add your app Id in developer`s account

  1. Open and login in your account
  2. Create a new app id and click on configure Push notifications.
  3. There are two push notification certificates  (Development and Distribution). As we want to test the certificates for development , click on development push notification certificate.
  4. Upload the CSR which you`v created earlier on the upload CSR tab and download your push notification certificate.

Step 4 : Add provisioning profile :

  1. Create a new development certificate and add your devices in it .
  2. 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

  1. For that , Go the terminal in your mac
  2. Type cd space location where you`v save p12 file . e.g. cd Saurabh
  3. 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 )
  4. It will ask for your phase password which you`v set earlier. Enter that.
  5. 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 🙂