【发布时间】:2013-10-09 15:32:46
【问题描述】:
我确定这个问题在某处重复,但我找不到解决方案。我正在制作一个应用程序,其中一个功能允许用户选择他们将收到本地通知的日期和时间。
他们可以选择他们喜欢的一天中的任何时间,并且可以切换一周中的不同日子(周一、周二、周三等)。通知将每周发送一次。因此,我将用户限制为仅创建 3 个通知 - 如果选择了所有 7 天,我会将 repeatInterval 设置为每天(一个通知)。如果为每 3 个通知选择 6 天,那么我将需要为每一天提供一个单独的通知(总共 3x6=18 个通知)。很可能只会使用 1 个通知,所以这很好。
我知道如何设置未来某个时间的通知,但如何设置周一下午 6 点的通知?
以下是我用于测试的代码。它会在未来 4 秒内设置警报(我是从 applicationDidEnterBackground 调用它)。
NSDateComponents *changeComponent = [[NSDateComponents alloc] init];
changeComponent.second = 4;
NSCalendar *theCalendar = [NSCalendar currentCalendar];
NSDate *itemDate = [theCalendar dateByAddingComponents:changeComponent toDate:[NSDate date] options:0];
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
localNotif.fireDate = itemDate;
localNotif.timeZone = [NSTimeZone defaultTimeZone];
localNotif.repeatInterval = NSWeekdayCalendarUnit;
【问题讨论】:
-
@Patrick, rmaddy:伙计们,你们找到解决方案了吗?
标签: ios objective-c uilocalnotification