iOS:为什么我的重复规则没有添加?

时间:2014-03-22 14:05:41

标签: ios calendar

我正在创建带闹钟的提醒。他们工作正常。现在我想添加重复规则,使用以下代码:

            EKRecurrenceFrequency frequency;
            int anzahl;

            unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit |  NSDayCalendarUnit;
            NSDate *now = [NSDate date];
            NSCalendar *gregorian = [NSCalendar currentCalendar];
            NSDateComponents *compsMax = [gregorian components:unitFlags fromDate:now];
            [compsMax setYear:[compsMax year] + 100];
            NSDate *hundredYearsLater = [gregorian dateFromComponents:compsMax];
            NSDate *endDate = hundredYearsLater;
            EKRecurrenceEnd *end = [EKRecurrenceEnd recurrenceEndWithEndDate:endDate];

            if ([_wiederholungCode isEqualToString:@"taeglich"]) {
                frequency = EKRecurrenceFrequencyDaily;
                anzahl = 1;
            } else if ([_wiederholungCode isEqualToString:@"monatlich"]) {
                frequency = EKRecurrenceFrequencyMonthly;
                anzahl = 1;
            } else if ([_wiederholungCode isEqualToString:@"vierteljaerlich"]) {
               frequency = EKRecurrenceFrequencyMonthly;
               anzahl = 3;
            } else if ([_wiederholungCode isEqualToString:@"halbjaerlich"]) {
                frequency = EKRecurrenceFrequencyMonthly;
                anzahl = 6;
            } else if ([_wiederholungCode isEqualToString:@"jaerlich"]) {
                frequency = EKRecurrenceFrequencyYearly;
                anzahl = 1;
            } else {
                frequency = EKRecurrenceFrequencyMonthly;
                anzahl = 1;
            }
            EKRecurrenceRule *rule = [[EKRecurrenceRule alloc] initRecurrenceWithFrequency:frequency interval:anzahl end:end];
           [reminder addRecurrenceRule:rule];
           NSLog(@"reminder.recurrenceRules: %@", reminder.recurrenceRules);

在日志中,直接添加规则后:reminder.recurrenceRules: ( "EKRecurrenceRule <0x156b9bb0> RRULE FREQ=MONTHLY;INTERVAL=1;UNTIL=21140321T230000Z",因此似乎规则已正确创建,但是,它未添加到规则数组中。

有人能帮助我吗?

注意:正确添加提醒本身及其警报。

1 个答案:

答案 0 :(得分:0)

似乎重复规则仅在提供日期时才有效。所以我在我的提醒中添加了开始日期和截止日期,然后就可以了(我没有测试是否只提供开始日期或截止日期)