Method called when selecting a banner of push notifications

I have a push notification that I send to the user, and I want to be able to take action when they click on it. I know that if the application is in the foreground, in the background, or if the user selects a warning from the notification center that the following method is being called in the application delegate:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 

However, if the application does not start, and the user clicks on the notification banner, as soon as the notification arrives, this method does not seem to be called. Is they another method that I need to influence this situation? Are there other cases where other methods should also be implemented?

+4
source share
1 answer

If the application does not start when you click on the notification banner, you will get an NSDictionary in application:didFinishLaunchingWithOptions:

Then you can just do something like this:

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { NSDictionary *pushDict = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; if(pushDict) { [self application:application didReceiveRemoteNotification:pushDict]; } } 

Also, in your application:didReceiveRemoteNtification: you can check to see if your application was inactive at the time you received the notification, for example:

 -(void)application:(UIApplication *)app didReceiveRemoteNotification:(NSDictionary *)userInfo { if([app applicationState] == UIApplicationStateInactive) { NSLog(@"Received notifications while inactive."); } else { NSLog(@"Received notifications while active."); } 
+4
source

All Articles