Receive a push notification while the application is not running iPhone

I am working on a single iPhone application that includes a push notification. As I saw in many documents and tutorials, he suggests registering for push notifications using

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

as below:

- (BOOL)application:(UIApplication *)application 
  didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{   
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert| UIRemoteNotificationTypeBadge|  UIRemoteNotificationTypeSound]; 

    ...
} 

Now the question is, if the application was not running (even in the background) when there is a press, it cannot process the push message, but if I use the push message again from the notification area and again dine the application, I can get your message.

What do I need to do so that my application receives a push message, even when it is the first lunch?

+2
source share
1 answer

, . push- , registerForRemoteNotificationTypes: , , push- .

, , : .

, options, application:didFinishLaunchingWithOptions:. , , , , , push- , .

application:didFinishLaunchingWithOptions: :

NSDictionary *pushNotificationPayload = [launchOptions valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if(pushNotificationPayload) {
    [self application:application didReceiveRemoteNotification:pushNotificationPayload];
}
+6

All Articles