saveEvent返回“没有设置日历”

我试图从我的应用程序中将事件保存到日历中。 我的代码适用于iOS 7,但在iOS 6上 ,它返回没有设置日历。

应用程序会提示用户在iOS 7上授予对日历的访问权限。但iOS 6不会显示此类提示。虽然应用程序已被授予“ 设置” – >“隐私” – >“日历”的访问权限

是的,我已经实现了requestAccessToEntityType:completion:

这是我的代码片段

 EKEventStore *objStore = [[EKEventStore alloc]init]; if ([objStore respondsToSelector:@selector(requestAccessToEntityType:completion:)]) { // iOS 6 and later [objStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) { dispatch_async(dispatch_get_main_queue(), ^{ if (granted) { // code here for when the user allows your app to access the calendar EKEvent *calEvent = [EKEvent eventWithEventStore:objStore]; calEvent.title = mstrTitleEvent; calEvent.startDate = self.dateToBeSet; calEvent.endDate = self.dateToBeSet; calEvent.calendar = objStore.defaultCalendarForNewEvents; EKAlarm *objAlarm = [EKAlarm alarmWithAbsoluteDate:self.dateToBeSet]; [calEvent addAlarm:objAlarm]; NSError *error; BOOL _bStatus = [objStore saveEvent:calEvent span:EKSpanThisEvent commit:YES error:&error]; UIAlertView *alertV; if(_bStatus) { alertV = [[UIAlertView alloc]initWithTitle:@"Congratulations" message:@"Saved To Calendar" delegate:nil cancelButtonTitle:@"Right On!" otherButtonTitles:nil]; [alertV show]; } else { alertV = [[UIAlertView alloc]initWithTitle:@"Alert" message:[NSString stringWithFormat:@"Error saving to calendar, with error %@.",[error localizedDescription]] delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:nil]; [alertV show]; } } else { // code here for when the user does NOT allow your app to access the calendar UIAlertView *alertV = [[UIAlertView alloc]initWithTitle:@"Alert" message:@"Please grant access to the calendar, and try again later." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; [alertV show]; } }); }]; 

}

只是设法以某种方式find我的问题的解决scheme。 我不得不从一个页面导航到另一个页面,所以把链接张贴到这两个页面。

首先 – > https://discussions.apple.com/message/16497282#16497282

然后,从那里到 – > https://discussions.apple.com/message/16479587#16479587

我不得不进入设置> iCloud>并打开日历 。 之后,我试图尝试并运行我的代码,并且再次运行良好。

如果您遇到类似问题,请尝试此操作。

我正在使用iPad 2,并在设备上安装了iOS 6.1.3。

令人惊讶的是,我正在两个不同的设备上testing我的代码,一个工作正常,另一个则不工作。 只是看着设置,与它不工作的人有iCloud日历和提醒closures,只要打开它,现在一切正常…这必须是一个错误