Objective c 目标C-iCal未在iOS 9中创建自定义日历和新事件
这在iOS 8中工作得非常好 但在iOS 9中产生问题。以下是代码:Objective c 目标C-iCal未在iOS 9中创建自定义日历和新事件,objective-c,iphone,ios8,ios9,icalendar,Objective C,Iphone,Ios8,Ios9,Icalendar,这在iOS 8中工作得非常好 但在iOS 9中产生问题。以下是代码: self.eventManager.eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) { if (granted) { // Create a new calendar. EKCalendar *calendar =
self.eventManager.eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
if (granted) {
// Create a new calendar.
EKCalendar *calendar = [EKCalendar calendarForEntityType:EKEntityTypeEvent
eventStore:self.eventManager.eventStore];
// Set the calendar title.
calendar.title = @"<APP name>";
calendar.CGColor=APP_Blue_COLOR.CGColor;
// Find the proper source type value.
for (int i=0; i<self.eventManager.eventStore.sources.count; i++) {
EKSource *source = (EKSource *)[self.eventManager.eventStore.sources objectAtIndex:i];
EKSourceType currentSourceType = source.sourceType;
if (currentSourceType == EKSourceTypeLocal) {
calendar.source = source;
break;
}
}
// Save and commit the calendar.
NSError *error;
[self.eventManager.eventStore saveCalendar:calendar commit:YES error:&error];
// If no error occurs then turn the editing mode off, store the new calendar identifier and reload the calendars.
if (error == nil) {
// Turn off the edit mode.
// Store the calendar identifier.
[self.eventManager saveCustomCalendarIdentifier:calendar.calendarIdentifier];self.eventManager.selectedCalendarIdentifier=calendar.calendarIdentifier;//chirag
}
else{
// Display the error description to the debugger.
NSLog(@"CREATE_CALENDER %@", [error localizedDescription]);
}
}
else
{
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"" message:@"Please give permission to access your iPhone calender." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles: nil];
[alert show];
}
}];
它在内部给出以下错误,但将在NSError对象中返回:
Error getting shared calendar invitations for entity types 3 from daemon: Error Domain=EKCADErrorDomain Code=1014 "(null)"
问题是,当iCloud日历打开时,它会对日历应用程序隐藏本地创建的日历。要绕过此问题,解决方案是向iCloud源添加新日历:
for (EKSource *source in self.eventStore.sources)
{
if (source.sourceType == EKSourceTypeCalDAV &&
[source.title isEqualToString:@"iCloud"]) //This is a patch.
{
localSource = source;
break;
}
}
if (localSource == nil)
{
for (EKSource *source in self.eventStore.sources)
{
if (source.sourceType == EKSourceTypeLocal)
{
localSource = source;
break;
}
}
}
遇到同样的问题。你找到解决办法了吗?
for (EKSource *source in self.eventStore.sources)
{
if (source.sourceType == EKSourceTypeCalDAV &&
[source.title isEqualToString:@"iCloud"]) //This is a patch.
{
localSource = source;
break;
}
}
if (localSource == nil)
{
for (EKSource *source in self.eventStore.sources)
{
if (source.sourceType == EKSourceTypeLocal)
{
localSource = source;
break;
}
}
}