Friday, 22 January 2016

Apple Push Notifications Service (APNS) for Objective c

In this tutorial , i will tell your about APNS (Apple Push Notifications Service). APNS is used to send notifications to iOS devices like iPhone , iPad .




Apple Push Notifications includes :

1.  Badges
2.  Sounds
3.  Text Alets

Requirements for APNS :

1.  You need a paid iOS developer account.
2.   iOS device (iPhone or iPad) (Push notifications can`t be tested on simulator).


Step 1 :

Create a CSR certificate

1.  Open Keychain access .
2.  On the top toolbar , go to Keychain access >> Certificate assistant >> Request a certificate from the certificate authority .
3.   Enter your email address, common name when prompt.
4.  Click on save to disk and choose the location where you want to save the csr certificate.


Step 2 :

Enable Push notifications and configure them for your application.

1.   Login to Apple developers account.
2.   Go to App id`s and create a new app id. You have to fill in the name of your application and the bundle identifier for your application. (Bundle identifier should be same as your project bundle identifier).
3.   After creating you app id , you need to edit it and configure your push notifications .
4 . Create push notifications for development and add the csr certificate which you have created earlier .
5.  Your push notification certificate for development has been created , Download the certificate .


Step 3 :

Create p12 file

1.  Open the downloaded certificate ,  and expand it. You will see a private key .
2.  Select both certificate and private key and export them into .p12 file.
3.  Enter the phase password, and then yours mac password.
4. p12 file is now been created.

Step 4 :

Convert p12 into pem file.

We have to convert p12 file into pem file because we have to link PEM file with server , so that we can receive push notifications from server.

1.  Open terminal.
2.  Write cd (Location where you have stored the p12 file ). e.g..  cd desktop
3.  Write a command in terminal which will convert p12 file into PEM file :

      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.  Your PEM file is now been created.



Step 5 :


Configure AppDelegate of your project.


You have to configure AppDelegate , to enable push notifications .


1.  Go to appDelegate.m in your project.

2. Add the following code to enable push notifications to your project and get a device token :


Use deviceTokenString to send push notifications to your device.

Step 6 :

You can check online weather your Push notifications are working fine or not by visiting CHECK APNS ONLINE


Thats all about Apple Push Notification Service .

Thank you :) 

12 comments:

  1. Hi,
    I am new in iOS development and now our app need push notification, i already implemented what you suggest in this article and while testing 'http://apns-gcm.bryantan.info' i got the success message but no push notification comes to my device. Can you please guid me a bit ?

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
    2. Hi Bishnu , Are you using valid device id for send push notifications . ?

      Delete
    3. add didreceiveremotenotification method to get push notification on your device.

      Delete
  2. This comment has been removed by the author.

    ReplyDelete
  3. can you please tell me how to add push notification service for hybrid apps.

    ReplyDelete
  4. Thank you so much..Very nice.. Your way of explaining is very nice..I really gain some knowledge about the push notification...
    Keep updating..
    No.1 IOS Training Institute in Chennai | Best Android Training Institute in Chennai | Java Training Institute in Chennai

    ReplyDelete
  5. Nice and good article.. it is very useful for me to learn and understand easily.. thanks for sharing your valuable information and time.. please keep updating.
    No.1 Software Testing Training Institute in Chennai | Best Selenium Training Institute in Chennai | ISTQB Certification Center in Velachery

    ReplyDelete
  6. i am getting some issue in my developer account in stpe 2 i am login and then i don't have a push notification option then what can i do pls help me if any one know thank you :)

    ReplyDelete