在我的应用程序中,如果我的应用程序从后台终止,我想在特定时间设置本地通知,否则如果我的应用程序处于运行状态,那么我不想显示本地通知
我已经为本地通知编写了代码
NSCalendar *calendar1 = [NSCalendar autoupdatingCurrentCalendar];
// Get the current date
NSDate *pickerDate1 =self.dateEvening;//[self.dateEvening dateByAddingTimeInterval:60*1];// [self.pickerView date];
// Break the date up into components
NSDateComponents *dateComponents1 = [calendar1 components:( NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit )
fromDate:pickerDate1];
NSDateComponents *timeComponents1 = [calendar1 components:( NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit )
fromDate:pickerDate1];
NSDateComponents *dateComps1 = [[NSDateComponents alloc] init];
[dateComps1 setDay:[dateComponents1 day]];
[dateComps1 setMonth:[dateComponents1 month]];
[dateComps1 setYear:[dateComponents1 year]];
[dateComps1 setHour:[timeComponents1 hour]];
[dateComps1 setMinute:[timeComponents1 minute]];
[dateComps1 setSecond:[timeComponents1 second]];
NSDate *itemDate1 = [calendar1 dateFromComponents:dateComps1];
[dateComps1 release];
UILocalNotification *localNotif1 = [[UILocalNotification alloc] init];
if (localNotif1 == nil)
return;
localNotif1.fireDate = itemDate1;
localNotif1.timeZone = [NSTimeZone defaultTimeZone];
localNotif1.alertBody = @"Open application";
localNotif1.alertAction = @"View";
localNotif1.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif1];
[localNotif1 release];
如果应用程序将从后台关闭,上面的代码可以正常工作,但如果我的应用程序处于运行状态,那么我不希望触发本地通知。