2011-05-09 38 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); 
    } 
}]; 
相關問題