PDA

View Full Version : Can we read all events at once of iphone calendar in programmatic way?




sampadac
May 11, 2011, 12:44 AM
Hi,

I want to know that, Can we read all events at once of iphone calendar in programmatic way?

I know the way by which we can retrive events of known days. Following code retrive the events for current date. But how can I retrive all saved events in iphone calendar ie. not depending on dates?


NSDate *startDate = [NSDate date];

// endDate is 1 day = 60*60*24 seconds = 86400 seconds from startDate
NSDate *endDate = [NSDate dateWithTimeIntervalSinceNow86400*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];



Thanks,
Sampada.



robbieduncan
May 11, 2011, 04:08 AM
The documentation make it reasonably clear that you can't. Of course you can simply use the distantPast (http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSDate_Class/Reference/Reference.html#//apple_ref/occ/clm/NSDate/distantPast) and distantFuture (http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSDate_Class/Reference/Reference.html#//apple_ref/occ/clm/NSDate/distantFuture) NSDates as the start and end date and get everything that way.

sampadac
May 11, 2011, 04:20 AM
Ok...
Thanks.