背景情報
NSDate
の日付として使用されるオブジェクトを含むクラスがありますEKEvent
。は、イベントの実際の日付の x 日前の日付でEKEvent
、場合によってはセットでカレンダーに追加されます。EKRecurrenceRule
たとえば、dateOfEvent が 2013 年 2 月 1 日で、ユーザーが 2 日前にアラートを受け取ることを選択した場合、イベントは 2013 年 1 月 30 日にカレンダーに追加されます。
前の日付を取得する方法は次のとおりです。
NSDateComponents *components = [[NSDateComponents alloc] init];
components.day = ([daysPrior integerValue] * -1);
NSDate *alertDate = [[NSCalendar currentCalendar] dateByAddingComponents:components
toDate:[myClass dateOfEvent]
options:0];
現在の問題
を設定するEKRecurrenceRule
とEKRecurrenceFrequencyMonthly
各月のalertDateから月の何日かを選択します。上記の例では、その日は最終的に 30 日になりますが、2 月には 30 日がなく、イベントが 2 月に追加されることはありません。特定の数値に基づくのではなく、各月の前日を実際に設定するにはどうすればよいですか?
失敗した試行
繰り返しルールに負の日を追加して、設定したイベントの日付に基づいて逆行することを望んでいましたが、代わりにカレンダーの毎日にイベントが追加されました。
NSMutableArray *daysOfMonth = [[NSMutableArray alloc] init];
int x;
for (x = 0; x > -31; x--) {
[daysOfMonth addObject:[NSNumber numberWithInt:x]];
}
EKRecurrenceRule *rule = [[EKRecurrenceRule alloc] initRecurrenceWithFrequency:EKRecurrenceFrequencyMonthly
interval:1
daysOfTheWeek:nil
daysOfTheMonth:daysOfMonth
monthsOfTheYear:nil
weeksOfTheYear:nil
daysOfTheYear:nil
setPositions:nil
end:nil];