if ([eventStore.calendars count] == 0)
{
NSLog(@"No calendars are found.");
return NO;
}
EKCalendar *targetCalendar = nil;
/* Try to find the calendar that the user asked for */
for (EKCalendar *thisCalendar in eventStore.calendars){ line2
if ([thisCalendar.title isEqualToString:paramCalendarTitle] &&
thisCalendar.type == paramCalendarType){
targetCalendar = thisCalendar;
break;
}
}
Run Code Online (Sandbox Code Playgroud)
第1行和第2行收到错误:"不推荐使用的日历:在IOS 6中首先弃用"
如何解决?
相反,您必须使用以下方法.
- (NSArray *)calendarsForEntityType:(EKEntityType)entityType;
NSArray *cals = [eventStore calendarsForEntityType: EKEntityTypeEvent];
Run Code Online (Sandbox Code Playgroud)
并cals在line2中使用该数组.
请查看此处的文档