iphone - 如何在工作日的选择列表中设置重复的 UILocal 通知

标签 iphone objective-c uilocalnotification localnotification

我已经使用以下链接实现了UILocal Notification

http://useyourloaf.com/blog/2010/07/31/adding-local-notifications-with-ios-4.html

而且我修改了它以通过使用在每一天设置重复通知

//To set the repeat notification
            notif.repeatInterval = NSDayCalendarUnit;

例如 每天上午 10 点

但我的要求是用户需要在选定的工作日(周一到周六)设置通知

为什么因为用户可能有每周假期,例如(周六和周日)/周五 - 周日)/其他一些日子..

休息周他不应该触发通知。

因此,我们希望用户设置选定的工作日,通知将仅在这些日子设置。一旦用户设置了通知。

例如:

我们有 周日、周一、周二、周三、周四、周五、周六的列表

在那些用户上选择星期一、星期二、星期三、星期四。并设置为上午 10 点

然后通知将在这些天的每天上午 10 点触发。

怎么做

最佳答案

UILocalNotification 的 API 在这方面非常有限 - 您必须手动安排 4 个事件,每周在用户选择的日期重复。<​​/p>

为星期一安排重复计时器的示例如下所示

NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
dateComponents.weekday = 2; // sunday = 1 ... saturday = 7
dateComponents.hour    = 10;

UILocalNotification *notification = //...
notification.repeatInterval = NSWeekCalendarUnit;
notification.fireDate       = [calendar dateFromComponents:dateComponents];

天数可以在 NSDateComponents Class Reference 中找到

关于iphone - 如何在工作日的选择列表中设置重复的 UILocal 通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15342546/

相关文章:

ios - 将 Sprite 添加到其他 Sprite 位置

objective-c - 在没有 UIViewController 的情况下加载 XIB 文件

objective-c - 多次调用 registerUserNotificationSettings

ios - 如何在 iOS 中监听通知关闭事件?

ios - WatchKit App 无法编译 : "error: WatchKit Extension doesn' t contain any WatchKit apps"

iphone - iOS 在 iPad 上触摸(自动)偏移

iphone - 是否有适用于 iOS 的字体演示应用程序?

ios - 将容器置于其他容器之上

objective-c - 各种 kIOPMAssertionType 的区别

ios - 从 Main.m 调用 UILocalNotification