This works great in iOS 8.
But creating the problem is in iOS 9. Here is the code:
self.eventManager.eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
if (granted) {
EKCalendar *calendar = [EKCalendar calendarForEntityType:EKEntityTypeEvent
eventStore:self.eventManager.eventStore];
calendar.title = @"<APP name>";
calendar.CGColor=APP_Blue_COLOR.CGColor;
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;
}
}
NSError *error;
[self.eventManager.eventStore saveCalendar:calendar commit:YES error:&error];
if (error == nil) {
[self.eventManager saveCustomCalendarIdentifier:calendar.calendarIdentifier];self.eventManager.selectedCalendarIdentifier=calendar.calendarIdentifier;
}
else{
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];
}
}];
This gives me a success message, but does not create an application calendar in the iPhone calendar.
Although I do not show it due to the lack of events for him. I also tried to set a new event.
But it gives me the following code and error when creating a new event.
EKEvent *event = [EKEvent eventWithEventStore:self.eventManager.eventStore];
event.title = title;
event.calendar = [self.eventManager.eventStore calendarWithIdentifier:self.eventManager.selectedCalendarIdentifier];
event.startDate = startDate;
event.endDate = endDate;
NSError *error;
if ([self.eventManager.eventStore saveEvent:event span:EKSpanThisEvent commit:YES error:&error]) {
return true;
}
else{
NSLog(@"%@", [error localizedDescription]);
return false;
}
It gives the following error internally, but returns an NSError in the object:
Error getting shared calendar invitations for entity types 3 from daemon: Error Domain=EKCADErrorDomain Code=1014 "(null)"
source
share