Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm having an issue where I create my EKCalendar and everything looks good but then when I go to list my calendars, it doesn't show up. I also go to check my calendar list in my calendar app but it is non existant. Any thoughts?

Here is my button code to create my calendar:

- (IBAction)one:(id)sender {
NSString* calendarName = @"My Cal";
EKCalendar* calendar;

// Get the calendar source
EKSource* localSource;
for (EKSource* source in eventStore.sources) {
    if (source.sourceType == EKSourceTypeLocal)
    {
        localSource = source;
        break;
    }
}

if (!localSource)
    return;

calendar = [EKCalendar calendarWithEventStore:eventStore];
calendar.source = localSource;
calendar.title = calendarName;

NSError* error;
bool success= [eventStore saveCalendar:calendar commit:YES error:&error];
if (error != nil)
{
    NSLog(error.description);
    // TODO: error handling here
}
NSLog(@"cal id = %@", calendar.calendarIdentifier);
}

And here is my button code to list the calendar, but my new calendar is never included!

- (IBAction)two:(id)sender {

NSArray *calendars = [eventStore calendarsForEntityType:EKEntityTypeEvent];

for (EKCalendar* cal in calendars){
    NSLog(@"%@",cal.title);
}

}

Thank you in advance!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
388 views
Welcome To Ask or Share your Answers For Others

1 Answer

I found a solution. The problem is that when iCloud calendars switched on, it hides the locally created ones from the calendar app. To bypass this problem the solution is to add a new calendar to iCloud source:

    for (EKSource *source in self.eventStore.sources)
    {
        if (source.sourceType == EKSourceTypeCalDAV && 
           [source.title isEqualToString:@"iCloud"]) //Couldn't find better way, if there is, then tell me too. :)
        {
            localSource = source;
            break;
        }
    }

    if (localSource == nil)
    {
        for (EKSource *source in self.eventStore.sources)
        {
            if (source.sourceType == EKSourceTypeLocal)
            {
                localSource = source;
                break;
            }
        }
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...