【问题标题】:Daily UILocalNotification firing more than once每日 UILocalNotification 触发不止一次
【发布时间】:2013-11-04 06:52:57
【问题描述】:

您好,我正面临一个奇怪的问题。实际上,我想在上午 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:00 一个,上午 10:00 另一个。为什么我会在上午 10:00 收到通知。我只安排在上午 8:00。我知道 UILocalNotification 库在大多数苹果设备上还有一些其他奇怪的问题/错误。我只是想确认我的代码中是否有错误,或者这是 UILocalNotification 库的奇怪行为。我不知道为什么 Apple 不努力解决许多开发人员报告的有关 UILocalNotification 的问题。

注意:我使用的是 Xcode 4.6 和 iOS 6.1

【问题讨论】:

  • :在您的日期中添加上午/下午。那是你的问题。 [格式化程序 setDateFormat:@"HH:mm a"];像这样设置你的日期格式
  • 在安排本地通知之前尝试[[UIApplication sharedApplication] cancelAllLocalNotifications];。而且,从内存管理的角度来看,您的代码并不好。将您的NSDate *date = [[NSDate alloc] init]; date = [formatter dateFromString:@"08:00"]; 行更改为NSDate *date =[formatter dateFromString:@"08:00"];,并删除[date release]; 行,并且在调度后不要忘记release 您本地的通知对象。希望这会有所帮助!

标签: ios iphone nsdate uilocalnotification


【解决方案1】:

这将是BEST 链接以获得您的答案。

【讨论】:

  • 这将是最好的评论..而不是作为答案
猜你喜欢
  • 1970-01-01
  • 2018-02-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多