我已经在我的应用程序中实现了通知。当通知被触发时,警报会消失,而无需从通知的警报视图中按确定或取消按钮,并且它也会从状态栏中消失。当应用程序触发通知在后台或前台时会发生这种情况。背后的原因是什么?
我想在用户按下 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] ;
}
谢谢..