0

コーディングでカレンダーを作成し、そのカレンダーにイベントを作成することに成功しました。コーディングでカレンダーを削除することはできますが、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);
    }
}
4

1 に答える 1

0

私も同じことを経験しました。iOS 5.0 では、カレンダーはリマインダーにも自動的に使用されるようです。リマインダー アプリからカレンダーを削除する必要があります。

プログラムで作成したカレンダーをカレンダーアプリから削除しようとして失敗しても通知すら来ないのはiOSのバグではないかと思います。

于 2012-08-01T07:24:57.230 に答える