我怎样才能将EKEvent标记为完整?

时间:2013-07-23 07:28:37

标签: ios calendar ekevent ekeventkit ekeventstore

如何让用户将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;
}

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

有什么可以更改(任何标记或bool)来更新和保存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)并更新。

请建议!!

谢谢!

1 个答案:

答案 0 :(得分:0)

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

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

修改
我们可以替代地使用EKEvent的eventIdentifier属性。

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