2014-12-05 123 views
1

我想在应用处于前台状态时显示通知弹出窗口,其中alertbody按照代码片段显示。
当应用程序处于后台状态时,它完全正常工作。在应用程序委托在前台弹出通知

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]; 
+2

我想你知道,当应用程序在前台状态的通知收到的applicationDidReceiveLocalNotification方法(不知道方法的名称虽然),从那里你可以显示警告 – channi 2014-12-05 12:30:02

+0

http://stackoverflow.com/a/23365259/2518805如果想显示通知像横幅。 – sanjeet 2014-12-05 12:55:06

回答

1

application:didreceiveLocalNotification方法,如果你想看到的nofication,而你的应用程序是在前台:

- (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]; 
    } 
}