Reputation: 1787
I'm currently building an iOS calendar app that can access the iphone's calendar to read/write from/to it, the problem that i'm facing is that my app should sync both my app's calendar and the iphone calendar, so if my app modifies an event it should get modified in the iphone 's calendar and vice versa.
an object of the class EKEvent doesn't seem to have an updatedAt property, and so i haven't got a way to say which one is the most up to date version of a given event, is it my app's or the iPhone's calendar one.
Is there a way to get when an ekevent was last modified?
thanks in advance.
Upvotes: 2
Views: 778
Reputation: 4906
Ok I tell you all I know about this, I hope to be helpful.
You're right, there's no last modified date as property for a single EKEvent. Only the EKCalendarItem has a property lastModifiedDate
but I'm not sure that can be useful in your case.
I found this interesting function:
#pragma mark - Calendar Changed
- (void)calendarChanged:(NSNotification *)notification {
EKEventStore *ekEventStore = notification.object;
NSDate *now = [NSDate date];
NSDateComponents *offsetComponents = [NSDateComponents new];
[offsetComponents setDay:0];
[offsetComponents setMonth:4];
[offsetComponents setYear:0];
NSDate *endDate = [[NSCalendar currentCalendar] dateByAddingComponents:offsetComponents toDate:now options:0];
NSArray *ekEventStoreChangedObjectIDArray = [notification.userInfo objectForKey:@"EKEventStoreChangedObjectIDsUserInfoKey"];
NSPredicate *predicate = [ekEventStore predicateForEventsWithStartDate:now
endDate:endDate
calendars:nil];
// Loop through all events in range
[ekEventStore enumerateEventsMatchingPredicate:predicate usingBlock:^(EKEvent *ekEvent, BOOL *stop) {
// Check this event against each ekObjectID in notification
[ekEventStoreChangedObjectIDArray enumerateObjectsUsingBlock:^(NSString *ekEventStoreChangedObjectID, NSUInteger idx, BOOL *stop) {
NSObject *ekObjectID = [(NSManagedObject *)ekEvent objectID];
if ([ekEventStoreChangedObjectID isEqual:ekObjectID]) {
// Log the event we found and stop (each event should only exist once in store)
NSLog(@"calendarChanged(): Event Changed: title:%@", ekEvent.title);
*stop = YES;
}
}];
}];
}
originally posted in this answer but it's seems that uses a private API.
Lastly, notice that in the property eventIdentifier
for a EKEvent:
If the calendar of an event changes, its identifier most likely changes as well.
Maybe this info can be helpful, see more in the Apple Documentation.
Upvotes: 2