繁体   English   中英

通知正在从iPhone的状态栏中消失

[英]Notification is being disappeared from statusbar in iphone

我已经在我的应用中实现了通知。 触发通知后,警报会消失,而无需从通知的警报视图中按“确定”或“取消”按钮,它也会从状态栏中消失。 当应用程序触发通知处于后台或前台时,就会发生这种情况。 背后的原因是什么?

我想显示通知警报,直到用户按下“确定”或“取消”按钮,我该如何实现?

我需要在通知设置中进行一些设置还是为此设置一些代码?

我的代码如下。

NSDateFormatter *dateFormatter3 = [[NSDateFormatter alloc] init];

[dateFormatter3 setDateFormat:@"dd/MM/yyyy / HH:mm:ss"];

NSDate *toDate = [dateFormatter3 dateFromString:timeBut.titleLabel.text];

[dateFormatter3 release];

NSLog(@"toDate=%@",toDate);

UILocalNotification *localNotification = [[UILocalNotification alloc] init]; //Create the localNotification object

[localNotification setFireDate:toDate]; //Set the date when the alert will be launched using the date adding the time the user selected on the timer

[localNotification setAlertAction:@"Launch"]; //The button's text that launches the application and is shown in the alert

 [localNotification setAlertBody:[remTextField text]]; //Set the message in the notification from the textField's text

 [localNotification setHasAction: YES]; //Set that pushing the button will launch the

 [localNotification setSoundName:UILocalNotificationDefaultSoundName];

 //[localNotification setApplicationIconBadgeNumber:1];

 [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; //Schedule the notification with the system

 [localNotification release];

 successalert=[[UIAlertView alloc] initWithTitle:@"DemoTable" message:@"Simple Reminder is successfully added" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];

 [successalert show];

  [successalert release];

我已经在appdelegate中实现了以下方法。

//Getting notification while running
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notif  
 {   
    UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"DemoTable"  message:notif.alertBody delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
    [alert show];
    [alert release];
    // delete the notification from the system
    [application cancelLocalNotification:notif] ;
  }

谢谢..

iOS6中的默认通知样式是在栏上显示通知。 在这种情况下,警报将显示几秒钟并消失,通知会保留在通知栏中,直到用户打开它为止。 这是通知中心的默认行为。 你不能改变它 您的应用程序用户必须决定警报的样式,无论他需要旧样式的警报通知还是在通知中心进行通知。 如果他从iPhone的设置中选择了旧样式警报,则只有您可以通过警报按钮操作提示用户打开应用。 否则,当用户从通知栏选择通知时,应用程序将打开。 这是用户偏好,您不能执行任何操作

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM