下一个EKReminder重复日期

时间:2014-05-06 00:25:04

标签: ios objective-c cocoa-touch eventkit

我正在尝试提醒警报响起的下一个日期,但EKAlarm属性没有返回任何值。

这是创建提醒的方式:

            EKReminder *reminder = [EKReminder reminderWithEventStore:self.eventStore];

            reminder.title = reminderTitle;

            reminder.calendar = [eventStore defaultCalendarForNewReminders];

            EKRecurrenceRule *recurrenceRule = [[EKRecurrenceRule alloc] initRecurrenceWithFrequency:EKRecurrenceFrequencyDaily interval:frequency end:nil];

            reminder.recurrenceRules = [NSArray arrayWithObject:recurrenceRule];

            NSCalendar *cal = [NSCalendar currentCalendar];
            unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit |  NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit;

            reminder.dueDateComponents = [cal components:unitFlags fromDate:[controller.reminderDatePicker date]];

            EKAlarm *alarm = [EKAlarm alarmWithAbsoluteDate:controller.reminderDate];

            [reminder addAlarm:alarm];

            NSError *error = nil;

            [eventStore saveReminder:reminder commit:YES error:&error];

这是我尝试访问下一个重复日期的时候。完全找到提醒,但alarm.absoluteDate为空。

[eventStore fetchRemindersMatchingPredicate:predicate completion:^(NSArray *reminders) {
            for (EKReminder *reminder in reminders) {

                NSLog(@"%@", reminderTitle);

                if ([reminder.title isEqualToString:reminderTitle]) {

                    reminderExists = [NSNumber numberWithBool:YES];
                    NSLog(@"reminder exists");
                    NSLog(@"after reminder exists is assigned to YES, value is %@", ([reminderExists boolValue]) ? @"True" : @"False");
                    if ([reminderExists boolValue]) NSLog(@"reminder exists variable works");

                    NSArray *alarms = reminder.alarms;

                    EKAlarm *alarm = [alarms objectAtIndex:0];

                    NSDateFormatter *nextReminderDateFormatter = [[NSDateFormatter alloc] init];
                    nextReminderDateFormatter.dateFormat = @"MM/dd/yyyy at hh:mm a";
                    NSString *nextReminderDateString = [nextReminderDateFormatter stringFromDate:alarm.absoluteDate];

                    nextReminderDate = alarm.absoluteDate;

                   //alarm.absolute date is null

                    NSLog(@"Next reminder is on %@", nextReminderDateString);


                }
            }

如何获得下一个重复日期?

0 个答案:

没有答案