2011-12-08 40 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中的第一個標識符(冒號前)是什麼。它似乎與日曆有關,但我不認識這個標識符。