开发者

How can I retrieve all events from an iPhone calendar?

I want to know how to read all events in an iPhone calendar in a programmatic way?

I know the way by which we can retrieve events of known days. The following code retrieves the开发者_运维百科 events for the current date. But how can I retrieve all saved events in an 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 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];


You can fetch events from a user’s Calendar database using three ways : 1)Fetching Events as a Event Store 2)Fetching Events with a Predicate 3)Fetching Individual Events with an Identifier

You can use either Predicate or Identifier, follow the IOS guidelines to see some examles and details.

hopes this Helps.


This bello code is used to get the all calender event from the device calendar just copy paste this below code you will get the all event

EventKitUI/EventKitUI.h -> import this file

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);
    }
}];


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜