1

我想知道如何以编程方式读取 iPhone 日历中的所有事件?

我知道我们可以检索已知日期的事件的方式。以下代码检索当前日期的事件。但是我怎样才能在 iPhone 日历中检索所有已保存的事件,即。不取决于日期?

NSDate *startDate = [NSDate date];

// endDate is 1 day = 60*60*24 seconds = 86400 seconds from startDate
NSDate *endDate = [NSDate dateWithTimeIntervalSinceNow:(86400*1)];

// Create the predicate. Pass it the default calendar.
NSArray *calendarArray = [NSArray arrayWithObject:defaultCalendar];
NSPredicate *predicate = [self.eventStore predicateForEventsWithStartDate:startDate endDate:endDate calendars:calendarArray]; 

// Fetch all events that match the predicate.
NSArray *events = [self.eventStore eventsMatchingPredicateredicate];
4

3 回答 3

1

您可以使用三种方式从用户的日历数据库中获取事件:1)将事件作为事件存储获取 2)使用谓词获取事件 3)使用标识符获取单个事件

您可以使用谓词或标识符,按照 IOS 指南查看一些示例和详细信息。

希望这会有所帮助。

于 2011-05-20T04:19:55.690 回答
1

此bello代码用于从设备日历中获取所有日历事件只需复制粘贴以下代码您将获得所有事件

EventKitUI/EventKitUI.h-> 导入这个文件

EKEventStore *store = [[EKEventStore alloc] init];
[store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
    if(granted) {
        NSDate* startDate = /* whatever value you want */
        NSDate* endDate = /* whatever value you want */
        NSPredicate *fetchCalendarEvents = [store predicateForEventsWithStartDate:startDate endDate:endDate calendars:nil];
        NSArray *eventList = [store eventsMatchingPredicate:fetchCalendarEvents];
        NSLog(@"allevent:%@",eventList);
    }
}];
于 2013-12-23T10:44:18.367 回答
0
NSDate* startDate = [NSDate distantPast];
NSDate* endDate = [NSDate distantFuture];
于 2011-05-09T09:48:32.213 回答