2013-01-13 36 views
1

我想通过新的iOS方法calendarItemWithIdentifier来查找日历事件。我无法使用eventWithIdentifier,因为在事件与服务器同步后标识符被更改。 calendarItemIdentifier不是。使用calendarItemWithIdentifier来查找日历事件

但calendarItemWithIdentifier总是返回(空)。

EKEventStore *store = [[EKEventStore alloc] init]; 

[store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) { 
    if (granted) { 

     // Create event. 
     EKEvent *event = [EKEvent eventWithEventStore:store]; 
     event.title = self.title; 
     event.startDate = [[NSDate date] dateByAddingTimeInterval:3600]; 
     event.endDate = [[NSDate date] dateByAddingTimeInterval:7200]; 
     event.timeZone = [NSTimeZone defaultTimeZone]; 
     event.calendar = [store defaultCalendarForNewEvents]; 

     BOOL success = [store saveEvent:event span:EKSpanThisEvent commit:YES error:&error]; 
     if (success) 
     { 
      NSString *calendarItemIdentifier = event.calendarItemIdentifier; 
      NSLog(@"Assigned identifier: %@", calendarItemIdentifier); 

      // Look up the event in the calendar. 
      event = (EKEvent *)[store calendarItemWithIdentifier:calendarItemIdentifier]; 
      if (event) { 
       NSLog(@"FOUND"); 
      } else { 
       NSLog(@"NOT FOUND"); 
      } 
     } 
    } 

}]; 

从日志:

2013-01-13 10:32:52.042 CalendarIntegration[6095:1303] Assigned identifier: C5FD3792-EBF1-4766-B27D-2767E5C8F3BE 
2013-01-13 10:32:52.043 CalendarIntegration[6095:1303] NOT FOUND 

帮助,将不胜感激。

+0

同样的问题在这里:( –

回答

0

根据文档,如预期的这种行为,link

与日历完全同步将失去这个标识符。您应该制定计划来处理标识符不再可通过缓存其他属性获取的日历。