如何正确识别一个ical事件

时间:2011-12-08 06:14:26

标签: ios cocoa-touch cocoa

在iOS中,EKEvent类有2个关于事件标识符的属性:eventIdentifier和uuid属性。当在mac上查看同一个同步事件时,CalEvent有一个uid属性,但在我的测试中没有一个匹配。

有人知道如何正确识别双方的事件?

2 个答案:

答案 0 :(得分:2)

如果您使用的是iOS 6,请尝试calendarItemExternalIdentifier。

  

此标识符允许您跨多个设备访问相同的事件或提醒。

我使用核心数据,iCloud和日历时遇到了这个问题。我捕获了eventIdentifier并将其保存到一台设备上的核心数据但是当我检查了另一台设备时,eventIdentifier在日历上发生了变化。
通过捕获calendarItemExternalIdentifier而不是eventIdentifier来解决它: iOS Reference

保存活动时捕获calendarItemExternalIdentifier:

- (void)eventEditViewController:(EKEventEditViewController *)controller
      didCompleteWithAction:(EKEventEditViewAction)action {
        NSError *error = nil;
        EKEvent *thisEvent = controller.event;
        switch (action) {
            case EKEventEditViewActionCanceled:
                 // Edit action canceled, do nothing.
            break;
            case EKEventEditViewActionSaved:
            {[self.selectedClientSession setEventIdentifier:[thisEvent calendarItemExternalIdentifier]];
            .......

在应用中显示活动时,查询活动是否属于我们的“会话”活动之一:

// Get the event e.g. from a tableview listing of events today    
   calendarEvent = (EKEvent*)[eventsList2 objectAtIndex:indexPath.row];
// Is this one of our session events? Build a predicate to query our clientSession objects by comparing the identifier we captured with the Event calendarItemExternalIdentifier
   self.sessionPredicate = [NSPredicate predicateWithFormat:@" eventIdentifier = %@ ",[calendarEvent calendarItemExternalIdentifier]
// Get the results
   [self setupFetchedResultsController];
//Check that calendarItemExternalIdentifier has been recorded in our session database  
   NSArray *sessionSet = [self.fetchedResultsController fetchedObjects];
//If no results then this is not a client session
   if (sessionSet.count == 0){
    // Just a regular event to display
   } else{
   //It is a client session - display and allow to do interesting stuff
   }

答案 1 :(得分:0)

EKEvent属性eventIdentifier的后半部分似乎包含CalEvent属性uid。我不知道eventIdentifier中的第一个标识符(冒号前)是什么。它似乎与日历有关,但我不认识标识符。