Ios 每天多次触发UILocalNotification

Ios 每天多次触发UILocalNotification,ios,iphone,nsdate,uilocalnotification,Ios,Iphone,Nsdate,Uilocalnotification,你好,我正面临一个奇怪的问题。事实上,我想在早上8:00安排一个每日通知(每天仅一次)。下面是我安排每日通知的代码 NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"HH:mm"]; NSDate *date = [[NSDate alloc] init]; date = [formatter dateFromString:@"08:00"]; UILocalNotifi

你好,我正面临一个奇怪的问题。事实上,我想在早上8:00安排一个每日通知(每天仅一次)。下面是我安排每日通知的代码

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"HH:mm"];
NSDate *date = [[NSDate alloc] init];
date = [formatter dateFromString:@"08:00"];
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = date;
localNotification.timeZone=[NSTimeZone defaultTimeZone];
localNotification.alertBody = @"You just received a local notification";
localNotification.alertAction = @"View Details";
localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.repeatInterval = NSDayCalendarUnit;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
[formatter release];
[date release];
我的问题是,我收到2个本地通知。一个在上午8点,另一个在上午10点。为什么我在上午10点收到通知。我只安排在早上8点。我知道UILocalNotification库在大多数苹果设备上还存在其他一些奇怪的问题/bug。我只是想确认我的代码中是否有错误,或者这是UILocalNotification库的一种奇怪行为。我不知道为什么苹果不致力于解决许多开发者报告的关于UILocalNotification的问题。


注意:我正在使用Xcode 4.6和iOS 6.1,这将是获取您答案的链接。

:在日期中添加am/pm。这是你的问题。[格式化程序setDateFormat:@“HH:mm a”];像这样设置日期格式尝试
[[UIApplication sharedApplication]cancelAllLocalNotifications]在安排本地通知之前。而且,从内存管理的角度来看,您的代码并不好。更改您的
NSDate*date=[[NSDate alloc]init];日期=[formatter dateFromString:@“08:00”]行到
NSDate*date=[formatter dateFromString:@“08:00”],并删除
[发布日期]行,也不要忘记在调度本地通知对象后释放它。希望这有帮助!这最好是作为评论,而不是回答