I'm trying to save an event using pyobjc, but I get an EKErrorDomain Code 11 ("That event does not belong to that event store").
Here's what I have so far:
ek_store = EKEventStore.alloc().initWithAccessToEntityTypes_(0)
print(f'{ek_store=}')
my_cal_identifier = 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'
my_calendar = ek_store.calendarWithIdentifier_(my_cal_identifier)
print(f'{my_calendar.eventStore()=}') # obviously ek_store
event = EKEvent.alloc().init()
event.setEventStore_(ek_store)
print(f'{event.eventStore()=}') # ek_store, of course
event.setStartDate_(my_startDate) # NSDate, declared earlier
event.setEndDate_(my_endDate) # NSDate, declared earlier
event.setCalendar_(my_calendar)
event.setTitle_('My new event')
ek_store.saveEvent_span_error_(
event, 0, None
) # this throws the EKErrorDomain error
I'm utterly confused by the error message: the calendar as well as the event have the right event store set (I have only one defined anyway). What does this error mean in this context?
What am I missing?
In the documentation, it says "Create a new event with the init(eventStore:) method of the EKEvent class."
So maybe my problem stems from not understanding how to correctly create a new event with pyobjc (init does not allow arguments, so how can I pass on the event store?).
You should create the Event using the
eventWithEventStore_method, e.g.:With that change the code works for me (well after making sure the interpreter had access to the calendar using
ek_store.requestAccessToEntityType_completion_).Using
setEventStore_probably doesn't work because it is not a documented API in Apple's documentation.