我已成功通过编码创建日历并在该日历中创建活动。我可以通过编码删除日历,但是当我选择iPhone的日历并删除新创建的日历时,此时删除不起作用。 请建议。
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);
}
}
答案 0 :(得分:0)
我认为iOS中可能存在一个错误,当您尝试从日历应用程序中删除以编程方式创建的日历失败时,您甚至无法收到通知。