Ranjit
Ranjit

Reputation: 4646

UILocalnotification not working after killing the app from background

I am working with UIlocalnotifications, So whenever a notification pops up,and user clicks on it I open ViewController , so whenever my app is in background, and when notification pops up and when user clicks on it or on the app icon, I am able to show the ViewController.

But whenever user kills the app from background, and when notification occurs, if he clicks on notification, I am able to show the ViewController, but if I click on app Icon, I am not able to show ViewController

Below is my code

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
 UILocalNotification *locationNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
    if (locationNotification) {
        // Set icon badge number to zero
        application.applicationIconBadgeNumber = 0;


       AlarmViewController *alarmView = [[AlarmViewController alloc]initWithNibName: @"AlarmViewController" bundle:nil];    
    UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:alarmView];
    [self.window.rootViewController presentViewController:navController animated:YES completion:nil];

    }
}

I tried to debug this problem, and what I found is that, whenever I click on the app icon, its not getting any localnotification.Only if I click on the notification, I get a localnotification. I dont know whenether this is a bug, or whether I am missing something.

So please help me out

Regards Ranjit.

Upvotes: 0

Views: 1595

Answers (1)

KudoCC
KudoCC

Reputation: 6952

It's not a bug! Handling Local and Remote Notifications in Apple's development library says

Handling Local and Remote Notifications

Let’s review the possible scenarios when the system delivers a local notification or a remote notification for an application.

The notification is delivered when the application isn’t running in the foreground. In this case, the system presents the notification, displaying an alert, badging an icon, perhaps playing a sound.

As a result of the presented notification, the user taps the action button of the alert or taps (or clicks) the application icon. If the action button is tapped (on a device running iOS), the system launches the application and the application calls its delegate’s application:didFinishLaunchingWithOptions: method (if implemented); it passes in the notification payload (for remote notifications) or the local-notification object (for local notifications).

If the application icon is tapped on a device running iOS, the application calls the same method, but furnishes no information about the notification . If the application icon is clicked on a computer running OS X, the application calls the delegate’s applicationDidFinishLaunching: method in which the delegate can obtain the remote-notification payload.

iOS Note: The application delegate could implement applicationDidFinishLaunching: rather than application:didFinishLaunchingWithOptions:, but that is strongly discouraged. The latter method allows the application to receive information related to the reason for its launching, which can include things other than notifications. The notification is delivered when the application is running in the foreground. The application calls its delegate’s application:didReceiveRemoteNotification: method (for remote notifications) or application:didReceiveLocalNotification: method (for local notifications) and passes in the notification payload or the local-notification object.

Upvotes: 5

Related Questions