Code for push notification in iOS

Step For Push notification

Step 1  ::  Write following in anywhere your  code……………………………………………..

[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];

Step 2 :: Add delegate methods of Push notification in AppDelegate

– (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {

    const void *devTokenBytes = [devToken bytes];

    self.registered = YES;

    [self sendProviderDeviceToken:devTokenBytes]; // this will send token to your server’s database


– (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {

    NSLog(@“Error in registration. Error: %@”, err);


Step 3 :: Method for Receive push notification…….

– (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {

    NSDictionary *apsInfo = [userInfo objectForKey:@“apsinfo”]; // This appsInfo set by your server while sending push

    NSString *alert = [apsInfo objectForKey:@“alert”];

    UIApplicationState state = [application applicationState];

    if (state == UIApplicationStateActive) {

        application.applicationIconBadgeNumber = 0;


        UIAlertView *alertview = [[UIAlertView alloc] initWithTitle:@“Push Notification”





        [alertview show];

        [alertview release];

    } else {

        [self setTabs:contentsInfo];



– (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex {

    if (buttonIndex != [alertView cancelButtonIndex]) {

     // User pressed YES, do your stuffs



See Apple Push Notification docs for details on implementation.


Mahendra yadav

Sr Mobile application developer

Lineage Technology.


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s

Create a free website or blog at

Up ↑

%d bloggers like this: