I am working on one iPhone app which involves a push notification. As I have seen in many documents and tutorials it suggests to register for push notification with in
You might be conflating the notion of registering for and receiving notifications. It is impossible for an app to receive a push notification before the registerForRemoteNotificationTypes:
method is called the first time, since this method provides the push token that is used to send push notifications in the first place.
So, you must be talking about receiving notifications under the two separate situations in which they can be delivered: upon initial app launch, and during the execution of the program.
In order to handle notifications of the first type, you must inspect the options
dictionary sent to application:didFinishLaunchingWithOptions:
. The following code shows how to route a notification received at launch to the delegate method that is called when a push notification arrives while the app is already running.
Place this in your application:didFinishLaunchingWithOptions:
override:
NSDictionary *pushNotificationPayload = [launchOptions valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if(pushNotificationPayload) {
[self application:application didReceiveRemoteNotification:pushNotificationPayload];
}