简体   繁体   English

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

[英]iOS: why is my recurrence rule not added?

I am creating reminders with alarms. 我正在创建带有警报的提醒。 They work fine. 他们工作正常。 Now i want to add recurrence rules, with this code: 现在,我想使用此代码添加重复规则:

            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);

In the log, directly after adding the rule: reminder.recurrenceRules: ( "EKRecurrenceRule <0x156b9bb0> RRULE FREQ=MONTHLY;INTERVAL=1;UNTIL=21140321T230000Z" , so it seems the rule is correctly created, however, it is not added to the rules array. 在日志中,直接添加以下规则: reminder.recurrenceRules: ( "EKRecurrenceRule <0x156b9bb0> RRULE FREQ=MONTHLY;INTERVAL=1;UNTIL=21140321T230000Z" ,因此似乎已正确创建了规则,但是未将其添加到规则数组。

Can anybody help me? 有谁能够帮助我?

Note: the reminder itself and its alarm is added correctly. 注意:提醒本身及其警报已正确添加。

Seems that recurrence rules only work if a date is supplied, too. 似乎重复规则仅在提供日期时才有效。 So I added start date and due date to my reminders and then it works (I did not test if only supplying a start date OR a due date will work) 因此,我在提醒中添加了开始日期和截止日期,然后它起作用了(我没有测试是否仅提供开始日期或截止日期可以工作)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM