2011-12-08 41 views
2

在iOS中,EKEvent类具有两个有关事件标识符的属性:eventIdentifier和uuid属性。当在mac上查看相同的同步事件时,CalEvent具有一个uid属性,但这些都不匹配我的测试。如何正确识别事件

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

回答

2

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

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

我有这个问题使用核心数据,iCloud和日历。我捕获了eventIdentifier并将其保存到一个设备上的核心数据,但是当我检查其他设备时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]]; 
      ....... 

当应用程序显示事件,查询事件是否一个
通过捕获,而不是eventIdentifier的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 
    } 
+0

c你使用'eventWithIdentifier:''calendarItemExternalIdentifier'? –

0

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