我在iOS7应用程序中首次运行我的应用程序时收到以下错误,我试图与现有项目集成,但无法弄清楚如何消除此错误。
“对日历守护程序的谓词调用失败:错误域= EKCADErrorDomain代码= 1013”
首次运行应用程序时触发错误的代码是:
NSMutableArray *events = [NSMutableArray arrayWithArray:[self.eventStore eventsMatchingPredicate:predicate]];
在使用谓词语句之前,是否需要检查eventStore(在最后一个函数中)是否为空?
函数定义如下:
此功能可确保用户已授予访问日历的权限。
// Prompt the user for access to their Calendar
-(void)requestCalendarAccess
{
if([self.eventStore respondsToSelector:@selector(requestAccessToEntityType:completion:)])
{
[self.eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error)
{
if (granted)
{
// The user has granted access to their Calendar; let's populate our UI with all events occuring in the next 24 hours.
[self accessGrantedForCalendar];
}
}];
}
}
授予权限时会调用以下函数。
// This method is called when the user has granted permission to Calendar
-(void)accessGrantedForCalendar
{
// Let's get the default calendar associated with our event store
self.defaultCalendar = PierceCalendar;
// Enable the Add button
self.addButton.enabled = YES;
// Fetch all events happening in the next 24 hours and put them into eventsList
self.eventsList = [self parseEventsByMonth];
}
该函数的第一行调用包含error cause语句的fetchEvents函数。
-(NSMutableArray *) parseEventsByMonth
{
NSMutableArray *allPierceEvents = [self fetchEvents];
....
return parsedEventsByMonth;
}
此函数执行在第一次运行应用程序时导致错误的语句([self.eventStore eventsMatchingPredicate:predicate])。
// Fetch all events happening in the next 24 hours
- (NSMutableArray *)fetchEvents
{
NSMutableArray *pierceEvents = [[NSMutableArray alloc] init];
//Create the end date components
NSDateComponents *oneYearAgoComponents = [[NSDateComponents alloc] init];
oneYearAgoComponents.year = -1;
NSDate *startDate = [[NSCalendar currentCalendar] dateByAddingComponents:oneYearAgoComponents
toDate:[NSDate date]
options:0];
NSDateComponents *oneYearFromNowComponents = [[NSDateComponents alloc] init];
oneYearFromNowComponents.year = 1;
NSDate *endDate = [[NSCalendar currentCalendar] dateByAddingComponents:oneYearFromNowComponents
toDate:[NSDate date]
options:0];
// We will only search the default calendar for our events
NSArray *calendarArray = [self.eventStore calendarsForEntityType:EKEntityTypeEvent];
// Create the predicate
NSPredicate *predicate = [self.eventStore predicateForEventsWithStartDate:startDate
endDate:endDate
calendars:calendarArray];
// Fetch all events that match the predicate
NSMutableArray *events = [NSMutableArray arrayWithArray:[self.eventStore eventsMatchingPredicate:predicate]];
for (EKEvent *event in events)
{
if (event.calendar == PierceCalendar) {
[pierceEvents addObject:event];
}
}
return pierceEvents;
}
答案 0 :(得分:2)
我在导致错误的行之前插入了语句以消除错误。
[self.eventStore reset];
我发现了以下提示:
calendarsForEntityType:EKEntityTypeReminder is empty first time, works subsequently