好的,我告訴你我所知道的一切,希望對你有幫助。
你是對的,沒有最後修改日期作爲屬性爲單個EKEvent。只有EKCalendarItem有一個屬性lastModifiedDate
,但我不確定這對您的情況是否有用。
我發現這個有趣的功能:
#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;
}
}];
}];
}
最初發布in this answer但它似乎是使用私有API。
最後,請注意,在屬性eventIdentifier
的EKEvent:
如果一個事件改變了日曆,其標識最有可能 也會改變。
也許這個信息會很有幫助,詳見the Apple Documentation。
它沒有出現,我檢查父類的更新時間戳(lastModifiedDate EKEvent從EKCalendarItem繼承),感謝提高。 – TheFuquan
我在NSObject * ekObjectID = [(NSManagedObject *)ekEvent objectID]上發現錯誤; 線 –