【问题标题】:UILocalNotification: Cancel all on specific daysUILocalNotification:在特定日期全部取消
【发布时间】:2012-11-14 01:05:42
【问题描述】:

我的应用只需要在工作日触发警报。 我的想法是安排每天的通知,但问题是我读到 64 个安排的通知是您可以拥有的最大值,而我的通知将总共有 120 个通知,因此无法做到这一点。

现在我想知道是否有办法取消周六和周日的所有通知。

我现在使用的代码在周末重复通知:

NSDateComponents *comps = [[NSDateComponents alloc] init];
    [comps setHour:8];
    [comps setMinute:25];
    NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSDate *fireDate = [gregorian dateFromComponents:comps];

    UILocalNotification *alarm = [[UILocalNotification alloc] init];

    alarm.fireDate = fireDate;
    alarm.repeatInterval = NSDayCalendarUnit;
    alarm.soundName = @"sound.aiff";
    alarm.alertBody = @"Message..";
    alarm.timeZone = [NSTimeZone defaultTimeZone];
    [[UIApplication sharedApplication] scheduleLocalNotification:alarm];

【问题讨论】:

  • 当您使用日期/时间初始化通知时,您可以随时查看工作日。你能告诉我你设置通知的代码吗?
  • @anatoliy_v 请查看我的第一个更新帖子,提前致谢。

标签: objective-c ios uilocalnotification


【解决方案1】:

看看[UIApplication scheduledLocalNotifications],你已经安排好了所有通知。

这是一个UILocalNotification 的数组。

用这个数组循环并查看通知的日期fireDate,然后执行:

[UIApplication cancelLocalNotification:theNotificationToDelete];

【讨论】:

  • 感谢您的回复,但我不知道您的意思。我的通知工作正常,但每天都会重复,我希望它在周六和周日全部取消。
  • 您已提前安排好每一天的所有通知?
  • 我刚刚创建了 24 个通知,并将重复设置为 Daily,因为 Apple 的限制我无法安排 120 个通知。
  • 我明白,但您可以使用 for 循环而不是 daily 参数安排每天的通知。
  • 你有任何示例代码我可以如何实现这一点,我应该从哪个方向开始编码?
猜你喜欢
  • 2014-02-24
  • 2013-03-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多