這將檢測更改的事件並在日期範圍內記錄事件標題。雖然,我最終沒有這樣做,因爲在實踐中我不知道日期範圍。我需要與我正在使用的所有事件進行比較,這意味着我需要刷新它們,因爲對象ID可能已經更改。這最終導致每個事件都沒有那麼有用,現在我每隔幾秒刷新一次更改,忽略細節。我希望蘋果改進這些通知。
#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;
}
}];
}];
}
任何線索,如果這將被接受AppStore?在這種情況下,objectID似乎是一個'私人api'調用。 – 2013-12-10 17:40:15
我只用於實驗,所以我不知道。我想我發現EKEvents會通過猜測它們是NSManagedObjects內部(因此是類型轉換)來響應objectID,但是看起來並不是這種情況。 – Symmetric 2013-12-11 03:51:23