1

如何让用户将 EKEvent 标记为完成?我目前正在获取某个日期的事件并将其显示在 UITableView 中。

// Fetching events happening in the next 24 hours with a predicate, limiting to the default calendar
- (NSArray *)fetchEventsForDate:(NSDate*)startDate
{
    [self.eventsList removeAllObjects];
    // endDate is 1 day = 60*60*24 seconds = 86400 seconds from startDate
    NSDate *endDate = [startDate dateByAddingTimeInterval:86400];


    NSMutableDictionary *eventsDict = [NSMutableDictionary dictionaryWithCapacity:1024];
    NSDate* currentStart = [NSDate dateWithTimeInterval:0 sinceDate:startDate];

//    int seconds_in_year = 60*60*24*365;
    int seconds_in_day = 60*60*24;


    // enumerate events by one year segment because iOS do not support predicate longer than 4 year !
    //while ([currentStart compare:endDate] == NSOrderedAscending) {

        NSDate* currentFinish = [NSDate dateWithTimeInterval:seconds_in_day sinceDate:currentStart];

        if ([currentFinish compare:endDate] == NSOrderedDescending) {
            currentFinish = [NSDate dateWithTimeInterval:0 sinceDate:endDate];
        }
        NSPredicate *predicate = [eventStore predicateForEventsWithStartDate:currentStart endDate:currentFinish calendars:nil];
        [eventStore enumerateEventsMatchingPredicate:predicate
                                          usingBlock:^(EKEvent *event, BOOL *stop) {
                                              if (event) {
                                                  [eventsDict setObject:event forKey:event.eventIdentifier];
                                              }
                                          }];       

    NSArray *events = [eventsDict allValues];

    return events;
}

我希望用户点击事件单元以将其标记为完成。

可以更改什么(任何标签或布尔值)来更新和保存该 EKEvent 以在将来将其显示为完整事件?

[self.eventStore saveEvent: myUpatedEvent span:EKSpanThisEvent error:&error];

我探索了

event.status, event.refresh, event.organizer, event.availability, etc.

但没有一个有用。

EKEventAvailability我试过

  [event setAvailability:EKEventAvailabilityUnavailable];
        NSError *error = nil;
        NSLog(@"Event Availbility:%d",event.availability); // It always returned -1;
        [self.eventStore saveEvent:event span:EKSpanThisEvent error:&error];
        if (error) {
            NSLog(@"Save Event errorDiscription:%@",error.description);
        }

但它没有更新和返回 -1 ( EKEventAvailabilityNotSupported) 和更新。

请推荐!!

谢谢!

4

1 回答 1

0

您可以availability将点击事件的 更改为EKEventAvailabilityUnavailable。如果事件完成,逻辑上它是不可用的,不是吗?

But if the event’s calendar does not support availability settings,
this property’s value is `EKEventAvailabilityNotSupported.`

编辑:
我们可以交替使用eventIdentifierEKEvent 的属性。

这是事件的唯一标识符。(只读)当用户点击事件时,我们可以将其存储在本地或 CoreData 中并用于未来目的。

于 2013-07-23T07:46:20.553 回答