EKCalendar Error

2019-09-03 22:00发布

问题:

I have an app that programmatically saves an EKEvent to you iOS calendar. Instead of it going to the default calendar you choose the calendar you wish it to be placed in. I am having a problem with the way you are picking it because some calendars work but not others.

回答1:

You are setting your event's calendar twice

[event setCalendar:c]; 
[event setCalendar:[[eventStore calendars]objectAtIndex:calendararray]]; 

Please tell me where do you get calendararray is it an array? i seems more like an indexKey.


Instead of passign the index of your selected calendar, pass its title, like this: [calendar title] or calendar.title. then using this title look for the one in the complete list of edit and noneditable.


UPDATE

Just do something like this:

EKCalendar *theSelectedCalendar;
// selectedCalendarTitle comes from your delegate instead of your index...

for (EKCalendar *thisCalendar in eventStore.calendars){
    if ([thisCalendar.title isEqualToString:selectedCalendarTitle]){
       [event setCalendar:thisCalendar];
    }
}

UPDATE 2

EKCalendar *theSelectedCalendar;
// selectedCalendarTitle comes from your delegate instead of your index...

for (int i=0; i<=([eventStore.calendars count]-1); i++) {
    if ([[[[eventStore calendars]objectAtIndex:i] title] isEqualToString:selectedCalendarTitle]){
       [event setCalendar:[[eventStore calendars]objectAtIndex:i]];
    } 
}

UPDATE 3

//Present the picker populated with the array: eventStore.calendars. This should return the index and store it in: indexOfSelectedCalendarFromEventSoreCalendars

if ([[[eventStore calendars] objectAtIndex:indexOfSelectedCalendarFromEventSoreCalendars] allowsContentModifications]){
  [event setCalendar:[[eventStore calendars] objectAtIndex:indexOfSelectedCalendarFromEventSoreCalendars]];

} else {
    NSLog(@"Selected calendar cannot be modified."); //Present the picker again for the user to select another calendar.
}