1

I want to display notification popup when app is in foreground state, with alertbody as per code snippets.
It is completely working when app is in background state.

UILocalNotification *notification = [[UILocalNotification alloc] init];
if (notification == nil)
    return;
NSDate *dt = [NSDate dateWithTimeInterval:10 sinceDate:[NSDate date]];
notification.fireDate = dt;
notification.timeZone = [NSTimeZone defaultTimeZone];

notification.alertBody = @"After 10Secs...";
notification.alertAction = @"View";
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
Shah Nilay
  • 778
  • 3
  • 21
  • 2
    I assume you know that when app is in foreground state the notification is received in applicationDidReceiveLocalNotification method(not sure about name of method though), from there you can show an alert – channi Dec 05 '14 at 12:30
  • http://stackoverflow.com/a/23365259/2518805 if want to show notification like banner. – sanjeet Dec 05 '14 at 12:55

1 Answers1

1

application:didreceiveLocalNotification method in your app delegate if you want to see the nofication while your app is in the foreground:

- (void)application:(UIApplication *)application
    didReceiveLocalNotification:(UILocalNotification *)notification
{
    //simply show a alert,but the standard one will not show up by itself
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"MyAlertView"
        message:notification.alertBody
        delegate:self cancelButtonTitle:@"OK"
        otherButtonTitles:nil];
    [alertView show];
    if (alertView) {
        [alertView release];
    }
}
Dharma
  • 3,007
  • 3
  • 23
  • 38