Three Steps to Create Push Notification Enabled iOS Application

Apple push notification service. As an iOS Developer we often heard the term APNS. Let’s explore this cool feature of iOS device. APNS is Apple push notification services. By using this service we can send required information to the respective user’s application accordingly. This seems quit confusing so lets make it simple and clear.

As iOS application provide a very negligible scope to tackle things when the application is in background. Apple has provided a solution to this. In spite of, let your application track what new is available for user on the server side. you can write a script on your server to let your application what all updates it has. You can send three type of information using APNS:

1. Message
2. Sound file
3. Badge count (Which will show on the top right of the application Icon).

Up to here we have understood what can we do using APNS? But now you must be wondering how can I implement to make my application use this feature.
So Let’s take it step by step:

1. Firstly We need to register our application for receiving remote notification.

– (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{
//this will register your application for push notification
[[UIApplication sharedApplication]
registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)];
return YES;
}

On successful register for remote notification, it will call UIApplication delegate method:

– (void) application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken

{
// Here you can implement web service method for sending
device token to application server.
}
But In case it fails to register for remote notification, it will call
UIApplication delegate method:
- (void)application:(UIApplication *)application
didFailToRegisterForRemoteNotificationsWithError:(NSError
*)error
{
}

2. Secondly, On Successful registration for remote notification. We need to send device token to our application server by using web service. Now application and server are ready to interact with each other. But still we need to travel miles before reaching the destination :).

3. Third and the most important step to follow, Which will enables Push notification at our device and server level. So what for we are waiting for lets finish it and enjoy Push notification on our application.

To create provisioning profile we need to follow instruction here, Or stay tuned for my next part of this tutorial.
Please click here to download Sample Push Notification

Written By: Pushpendra Singh, Software Developer, Mindfire Solutions

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s