如何让用户将 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
) 和更新。
请推荐!!
谢谢!