Clicky

iOS Dev Nugget 58 Implementing Push Notifications

.

Need to run a code review on your codebase? Hire me

A follow-up to tip #26 Do not prompt user to enable push notifications immediately, here's a few steps for how to implement push notifications in your app:

The class implementing UIApplicationDelegate has to implement:

  1. -application:didRegisterForRemoteNotificationsWithDeviceToken: to handle when registration is successful, e.g. you'd want to store the device token alongside a user account on your server and pass the token to APNS every time you initiate a push.
  2. -application:didFailToRegisterForRemoteNotificationsWithError: to handle when registration fails. Check the NSError* object.
  3. -application:didReceiveRemoteNotification: OR -application:didReceiveRemoteNotification:fetchCompletionHandler: to handle when a notification is received while the app is running, be it in the foreground or background.
  4. -application:willFinishLaunchingWithOptions: to handle when the app receives a push while it is not running. Check the dictionary for the UIApplicationLaunchOptionsRemoteNotificationKey key.


Your feedback is valuable: Do you want more nuggets like this?   Yes   or   No

.

Like this and want such iOS dev nuggets to be emailed to you, weekly?

Sign Me Up! or follow @iosdevnuggets on Twitter

.

View archives of past issues