我很抱歉,但 !我找到了答案;)
这是代码:
EKEventStore *eventStore = [[EKEventStore alloc] init];
NSDate *startDate = [NSDate date];
NSDate *endDate = [NSDate distantFuture];
//NSArray *calendarArray = [NSArray arrayWithObject:defaultCalendar];
NSPredicate *predicate = [eventStore predicateForEventsWithStartDate:startDate
endDate:endDate
calendars:nil];
NSArray *events = [eventStore eventsMatchingPredicate:predicate];
if ([eventStore respondsToSelector:@selector(requestAccessToEntityType:completion:)])
{
/* iOS Settings > Privacy > Calendars > MY APP > ENABLE | DISABLE */
[eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error)
{
if ( granted )
{
NSLog(@"User has granted permission!");
NSLog(@"events %@", events);
}
else
{
NSLog(@"User has not granted permission!");
}
}];
}
这是要求用户允许应用程序获取日历(默认情况下所有日历)
[eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error)