0

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

我想在用户按下 OK 或 Cancel 按钮之前显示通知警报,我该如何实现?

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

我的代码如下所示..

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

谢谢..

4

1 回答 1

0

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

于 2013-06-26T06:10:06.757 回答