2011-05-09 73 views
1

我想知道如何以编程方式阅读iPhone日历中的所有事件?如何从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]; 
+0

有你做到这一点? – 2011-08-14 19:31:12

回答

0
NSDate* startDate = [NSDate distantPast]; 
NSDate* endDate = [NSDate distantFuture]; 
+0

harakiri,你的回答不会返回任何事件。我试过了,也试过 ' NSDate * startDate = [NSDate dateWithTimeIntervalSinceNow:-10 * 365 * 86400]; NSDate * endDate = [NSDate dateWithTimeIntervalSinceNow:10 * 365 * 86400];' – 2011-06-15 19:39:20

1

可以提取采用了三种方式从用户的日历数据库事件:1)抓取活动作为抓取活动与谓语3)取回各个事件的标识符

一个事件存储2)您可以使用Predicate或Identifier,按照IOS指南查看一些检查和细节。

希望对您有所帮助。

+0

+1 @shahid:很好的答案。喜欢和upvoted – SNR 2012-01-10 08:58:14

1

这战时代码是用来从设备的日历 只要复制粘贴下面的代码的所有轧光机事件中,你将得到所有的事件

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); 
    } 
}]; 
相关问题