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:
-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.-application:didFailToRegisterForRemoteNotificationsWithError:
to handle when registration fails. Check theNSError*
object.-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.-application:willFinishLaunchingWithOptions:
to handle when the app receives a push while it is not running. Check the dictionary for theUIApplicationLaunchOptionsRemoteNotificationKey
key.
Your feedback is valuable: Do you want more nuggets like this? Yes or No
.