0

i have successfully created calendar by coding and create events in that calendar.I am able to delete the calendar by coding but when i select iPhone's calendar and delete newly created calendar this time delete not working. please suggest.

EKEventStore *eventStore = [[EKEventStore alloc] init];
EKCalendar *calendar = [EKCalendar calendarWithEventStore:eventStore];
calendar.title = CALENDAR_TITLE;

// 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;
    }
}

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.")
    self.calendarIdentifier = calendar.calendarIdentifier;
} else {
    NSLog(@"Error saving calendar: %@.", error);
}


// Delete Calendar
EKEventStore *eventStore = [[EKEventStore alloc] init];
EKCalendar *calendar = [eventStore calendarWithIdentifier:self.calendarIdentifier];
if (calendar) {
    NSError *error = nil;
    BOOL result = [self.eventStore removeCalendar:calendar commit:YES error:&error];
    if (result) {
        NSLog(@"Deleted calendar from event store.");
    } else {
        NSLog(@"Deleting calendar failed: %@.", error);
    }
}
priya
  • 57
  • 6

1 Answers1

0

I experienced the same. On iOS 5.0 it actually seems like the calendar is also used for reminders automatically. You need to delete the calendar from the reminders app.

I think it may be a bug in iOS that you don't even get a notification when you unsuccessfully try to delete a programmatically created calendar from the calendar app.

aaaabcv
  • 29
  • 3