【问题标题】:How to properly identify an ical event如何正确识别 ical 事件
【发布时间】:2011-12-08 06:14:26
【问题描述】:

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

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

【问题讨论】:

    标签: ios cocoa-touch cocoa


    【解决方案1】:

    如果您使用的是 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
       }
    

    【讨论】:

    • 你可以使用eventWithIdentifier:calendarItemExternalIdentifier 吗?
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-17
      • 2013-06-21
      • 1970-01-01
      • 1970-01-01
      • 2017-01-02
      相关资源
      最近更新 更多