I have the following method, for getting all events in the current day:
- (NSArray *)fetchEventsForToday {
NSDate *startDate = [NSDate date];
// endDate is 1 day = 60*60*24 seconds = 86400 seconds from startDate
NSDate *endDate = [NSDate dateWithTimeIntervalSinceNow:86400];
// Create the predicate. Pass it the default calendar.
NSArray *calendarArray = [NSArray arrayWithObject:defaultCalendar];
NSPredicate *predicate = [self.eventStore predicateForEventsWithSt开发者_如何学CartDate:startDate endDate:endDate calendars:calendarArray];
// Fetch all events that match the predicate.
NSArray *events = [self.eventStore eventsMatchingPredicate:predicate];
NSLog(@"array: %@", events);
return events;
}
If I check my NSLog I get the following object in the array:
2011-06-29 19:24:01.383 SimpleEKDemo[2945:207] array: (
"EKEvent <0x5118cd0> { EKEvent <0x5118cd0> {
title = Test;
calendar = EKCalendar <0x5105d60> {
title = Calendar;
type = Local;
account = (null);
allowsModify = YES;
color = 0.443137 0.101961 0.462745 1.000000
};
alarms = (null);
URL = (null);
lastModified = 2011-06-29 23:51:51 +0000
};
location = (null);
startDate = 2011-06-30 00:30:00 +0000;
endDate = 2011-06-30 01:30:00 +0000;
allDay = 0;
floating = 0;
recurrence = (null);
attendees = (null)
}",
"EKEvent <0x5118380> {EKEvent <0x5118380> {
title = Prueba;
calendar = EKCalendar <0x5105d60> {
title = Calendar;
type = Local;
account = (null);
allowsModify = YES;
color = 0.443137 0.101961 0.462745 1.000000
};
alarms = (null);
URL = (null);
lastModified = 2011-06-29 23:51:58 +0000};
location = (null);
startDate = 2011-06-30 00:30:00 +0000;
endDate = 2011-06-30 01:30:00 +0000;
allDay = 0;
floating = 0;
recurrence = (null);
attendees = (null)
}",
"EKEvent <0x5117f70> {EKEvent <0x5117f70> {
title = Numero;
calendar = EKCalendar <0x5105d60> {
title = Calendar;
type = Local;
account = (null);
allowsModify = YES;
color = 0.443137 0.101961 0.462745 1.000000
};
alarms = (null);
URL = (null);
lastModified = 2011-06-29 23:53:54 +0000};
location = (null);
startDate = 2011-06-30 00:30:00 +0000;
endDate = 2011-06-30 01:30:00 +0000;
allDay = 0;
floating = 0;
recurrence = (null);
attendees = (null)
}"
As you can see I have 3 object: "test", "Prueba" and "Numero" this title and the start and end date is all information that I need, but I don't know how to get it. Does anybody can help me, please?
Have you looked at the documentation for EKEvent
? The required properties are
title
startDate
endDate
Usage
NSArray *events = [self.eventStore eventsMatchingPredicate:predicate];
for ( EKEvent * event in events ) {
NSLog(@"Title: %@, Start Date: %@, End Date: %@", event.title, event.startDate, event.endDate);
}
精彩评论