I have figured out how to add a custom calendar within my iPhone app, but I can't figure out how to add that calendar to the device's Calendar. The event shows the correct calendar when viewed from within the app, but even when I tap on the calendar row for an event, my calendar is not in the list, and I have to cancel if I want to keep the calendar name correct. Is there a way to 'subscribe' to my locally created calendar so that I can see it from within the Calendar app on the device (obviously, I would also want it to sync with the user's computer, etc).
Asked
Active
Viewed 4,348 times
2 Answers
6
It has to do with iCloud. When iCloud is on, a calendar with a source that is local (EKSourceTypeLocal) will be hidden.

SAHM
- 4,078
- 7
- 41
- 77
-
Hello JPK, i need to used EKSourceTypeExchange in my ios app, so is it possible to sync up my calendar to my gmail account which is in settings->account section in iPhone or in iPad and if yes then how can i solve it,,, and i also want to retrive all my gmail account's calendar events into my iphone calendar(ical) .. so how can i do this ? – Apple Jul 03 '13 at 13:40
1
I've been struggling with this today and it all seems down to what Calendar settings I (and ultimately the end user) has on the device.
Personally I sync my GMail Calendars down in Exchange format - doing so prevents the "local" calendars from showing up.
By manipulating the EKSource dependant on the user's settings should display your calendar correctly - this works for my Exchange scenario see the EKSource Class reference for more scenarios. Consider checking for iCloud!
EKCalendar *calendar = [EKCalendar calendarWithEventStore:self.eventStore];
calendar.title = @"My Calendar";
EKSource *localSource = nil;
EKSource *defaultSource = [self.eventStore defaultCalendarForNewEvents].source;
if (defaultSource.sourceType == EKSourceTypeExchange) {
localSource = defaultSource;
} else {
for (EKSource *source in self.eventStore.sources) {
if (source.sourceType == EKSourceTypeLocal) {
localSource = source;
break;
}
}
}
if (localSource) {
calendar.source = localSource;
} else {
NSLog(@"Error: no local sources available");
}
NSError *error = nil;
BOOL result = [self.eventStore saveCalendar:calendar commit:YES error:&error];
if (result) {
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:calendar.calendarIdentifier forKey:@"Calendar"];
[userDefaults synchronize];
NSLog(@"Saved calendar to event store");
} else {
NSLog(@"Error saving Calendar");
}

Ben Hutchinson
- 221
- 2
- 8
-
Hello ben, i need to used EKSourceTypeExchange in my ios app, so is it possible to sync up my calendar to my gmail account which is in settings->account section in iPhone or in iPad and if yes then how can i solve it,,, and i also want to retrive all my gmail account's calendar events into my iphone calendar(ical) .. so how can i do this ? – Apple Jul 03 '13 at 13:36