EKSource calendarsForEntityType returns nil despite valid calendars

Since updating to Sonoma and using XCode 15.0.1 to adapt my app's code base to deal with new requirement for Full Access to calendars, I am simply unable to find ANY valid calendars of type EKEntityTypeEvent despite having about 8 different EKSources available (which I can see and access in the macOS Calendar app), and which do contain calendars I used to be able to read/write to before I updated to Catalina. But the call to EKSource's calendarsForEntityType function always returns nil.

I have successfully obtained Full Access permission (which in any case is obviously so because otherwise I would not get access to all the EKSource items). I've also rebooted several times. I have Calendar selected under Resource Access items for the app's capabilities.

Does anyone have any idea why, or a workaround? Looks like a potentially serious bug at this point.

Answered by gpdawson in 770074022

I found the apparent cause, by creating a new project containing the simplest possible code to try to replicate this issue, and gradually making changes to replicate specifics of the code usage in my app.

It seems that creating and using a second instance of EKEventStore was the cause of the issue. In previous macOS versions this did not cause any problem, and appeared to be valid usage. However, I have apparently been able to resolve the current problem by ensuring that I create and use only a single instance of EKEventStore in my app. Although the second instance I was creating on the fly does contain all the same EKSource entities, and used to return the same calendars in a call to calendarsForEntityType, it now it does not return any calendars at all in a call to calendarsForEntityType. I would suggest that this is a bug. Perhaps EKEventStore should in future be given a shared singleton property in the API.

Accepted Answer

I found the apparent cause, by creating a new project containing the simplest possible code to try to replicate this issue, and gradually making changes to replicate specifics of the code usage in my app.

It seems that creating and using a second instance of EKEventStore was the cause of the issue. In previous macOS versions this did not cause any problem, and appeared to be valid usage. However, I have apparently been able to resolve the current problem by ensuring that I create and use only a single instance of EKEventStore in my app. Although the second instance I was creating on the fly does contain all the same EKSource entities, and used to return the same calendars in a call to calendarsForEntityType, it now it does not return any calendars at all in a call to calendarsForEntityType. I would suggest that this is a bug. Perhaps EKEventStore should in future be given a shared singleton property in the API.

EKSource calendarsForEntityType returns nil despite valid calendars
 
 
Q