如何获取iPhone日历上已有的事件的startDate?

时间:2012-09-10 16:22:35

标签: objective-c ios xcode nsarray ekevent

我正在为自己创建一个应用程序,我需要访问已经在我的日历中的特定事件的startDate和endDate。我该怎么做呢?我已经尝试将事件列表存储到数组中但是一旦事件在数组中,有什么意义,我该如何访问它们?

1 个答案:

答案 0 :(得分:1)

您可以在数组中保存EKEvents的eventIdentifier属性。

EKEventStore *eventStore = [[EKEventStore alloc] init];
// Create the predicate from the event store's instance method

NSPredicate *predicate = [store predicateForEventsWithStartDate:oneDayAgo

                                                    endDate:oneYearFromNow

                                                  calendars:nil];



// Fetch all events that match the predicate

NSArray *eventsArray = [store eventsMatchingPredicate:predicate];

for (EKEvent *eventToCheck in eventsArray) {
    if ([eventToCheck.eventIdentifier isEqualToString:[eventsIdentifierArray objectAtIndex:i]]) {
        //Do your changes here
        NSLog(@"%@", eventToCheck.startDate);
        NSLog(@"%@", eventToCheck.endDate);
    }
}

Refer this