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.
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.