Enable push notifications in iPhone app

Here is how you can enable push notifications in your iPhone app:

1. The first thing that user need to do for registering push notification service on the client side is taking user’s approval for allowing push notifications for their app. To do so we need to add the following code snippet in AppDelegate.m file of your app:

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

{

…..

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

…….

}

2. If the user gives an approval for sending push notifications and alerts from the app then app needs to register the device on Push notification channel using the device token of the device.

-(void) application:(UIApplication *) application didRegisterForRemoteNotificationWithDeviceToken:(NSData *)deviceToken{

…..

…..

}

Incase you want to log if registering to particular Notification channel failure event then we can use the following code snippet:

-(void)application:(UIApplication  *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *) error{

…..

….

}

3. If notification is received when the app is in background or if notification is opened from notification panel then the following function would be called :

-(void)application:(UIApplication *)application didRecieveRemoteNotification:(NSDictionary *) userinfo{

…..

// userinfo will have the payload that you send along with push notification, which may include badge, sound, deeplinking payload etc.

}

4. Once you receive a notification we should remove the badges and notification from the notification panel. We can do this by adding following code snippet:

-(void)applicationDidBecomeActive:(UIApplication *)application{

…..

[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];

[[UIApplication sharedApplication] cancelAllLocalNotifications];

..

}

Following the 4 steps given above would enable your app to receive and act based on different push notifications. Feel free to reach me at

Thanks for dropping by !!! Feel free to reach me at naik899@gmail.com if you have any queries regarding this post.

Leave a Reply

Your email address will not be published. Required fields are marked *