I use to EventKit to create EKCalendar.
I try to create it using this method. when I test it in Simulator calendar creates (screenshot) and appears in default Calendar, but when I do the same on device it doesn't work, there are no errors , all the same but without result.
-(void)createCalendar{
EKEventStore *eventStore = [[EKEventStore alloc] init];
EKCalendar *calendar = [EKCalendar calendarForEntityType:EKEntityTypeEvent eventStore:eventStore];
calendar.title = @"my calendarik";
// Iterate over all sources in the event store and look for the local source
EKSource *theSource = nil;
for (EKSource *source in eventStore.sources) {
if (source.sourceType == EKSourceTypeLocal) {
theSource = source;
break;
}
}
NSString *iden = calendar.calendarIdentifier;
if (theSource) {
calendar.source = theSource;
} else {
NSLog(@"Error: Local source not available");
return;
}
NSError *error = nil;
BOOL result = [eventStore saveCalendar:calendar commit:YES error:&error];
if (result) {
NSLog(@"Saved calendar to event store.");
} else {
NSLog(@"Error saving calendar: %@.", error);
}
EKCalendar* calendar_;
NSArray *allCalendars = [eventStore calendarsForEntityType:EKEntityTypeEvent];
for (EKCalendar *cal in allCalendars) {
if ([cal.calendarIdentifier isEqualToString:iden]) {
calendar_ = cal;
break;
}
else {
calendar_ = [eventStore calendarWithIdentifier:iden];
}
}
`