2011-12-08 7 views
2

iOSでは、EKEventクラスにイベント識別子に関する2つのプロパティeventIdentifierとuuidプロパティがあります。 Mac上で同じ同期イベントをMacで見た場合、CalEventはuidプロパティを持ちますが、これらは私のテストでは一致しません。イベントを正しく識別する方法

誰かが両側のイベントを正しく識別する方法を知っていますか?

答えて

2

iOS 6を使用している場合は、calendarItemExternalIdentifierを試してください。

この識別子を使用すると、複数のデバイス間で同じイベントまたはリマインダーにアクセスできます。

この問題は、コアデータ、iCloudとカレンダーを使用して発生しました。 eventIdentifierをキャプチャして1つのデバイスのコアデータに保存しましたが、カレンダーで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]]; 
      ....... 

アプリにイベントを表示し、クエリはイベントが1である場合を
ではなく、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あなたは 'calendarItemExternalIdentifier'で' eventWithIdentifier: 'を使用しますか? –

0

EKEventプロパティeventIdentifierの後半には、プロパティuidが含まれているように見えます。 eventIdentifierの最初の識別子(コロンの前)が何であるか分かりません。それはカレンダーに関連しているようですが、私はその識別子を認識しません。