skip to Main Content

I am trying to create a small command line tool in Swift with Xcode 12.5.1 on macOS Big Sur to access and display calendar events. I’ve read the EKEventStore documentation and created the simplest possible code:

import Foundation
import EventKit

var store = EKEventStore()

I’ve turned on sandboxing, added the Calendar entitlement and sandbox entitlement.

I’ve added an Info.plist file with the Privacy – Calendars Usage Description key and value filled out.

In Build Settings, I’ve set "Create Info.plist Section in Binary" to "Yes".

But despite jumping through all these hoops, my one line app always fails to load the EKEventStore() with the following errors:

2021-09-17 23:39:24.609490-0700 nextzoom[51558:6213649] CoreData: XPC: Unable to load metadata: Error Domain=NSCocoaErrorDomain Code=134070 "An error occurred in the persistent store." UserInfo={Problem=request failed, insufficient permission}
2021-09-17 23:39:24.610959-0700 nextzoom[51558:6213649] [error] error: addPersistentStoreWithType:configuration:URL:options:error: returned error NSCocoaErrorDomain (134070)
CoreData: error: addPersistentStoreWithType:configuration:URL:options:error: returned error NSCocoaErrorDomain (134070)
CoreData: annotation: userInfo:
CoreData: annotation:   Problem : request failed, insufficient permission
CoreData: annotation: storeType: NSXPCStore
CoreData: annotation: configuration: (null)
CoreData: annotation: URL: file:///Users/%%%%%%/Library/Calendars/Calendar%20Cache
CoreData: annotation: options:
CoreData: annotation:   NSMigratePersistentStoresAutomaticallyOption : 1
CoreData: annotation:   agentOrDaemon : 1
CoreData: annotation:   NSInferMappingModelAutomaticallyOption : 1
CoreData: annotation:   serviceName : com.apple.CalendarAgent.database
CoreData: annotation:   NSPersistentHistoryTrackingKey : {
    NSPersistentHistoryTrackingEntitiesToExclude =     (
        ChangeRequest
    );
}
Program ended with exit code: 0

No permissions dialog box pops up. But if I add the contacts entitlement and Privacy – Contacts Usage Description then I do get a popup asking for permission to access contacts and the app appears in my Security and Privacy settings with Contacts access. But never for Calendar.

Here is a git repo of the Xcode project.

Any ideas what I’m doing wrong here?

2

Answers


  1. Did you manually request permission to access the EventStore?
    https://developer.apple.com/documentation/eventkit/ekeventstore/1507547-requestaccesstoentitytype

    The ContactStore weirdness seems to be a bug and has also been reported here: https://openradar.appspot.com/FB8918491

    Login or Signup to reply.
  2. I don’t know if you’re still having this issue, but just adding RunLoop.main.run() to the bottom of your swift code gets it to prompt me for calendar access.

    (Came across this trying to figure out a similar issue for CoreLocation, where @TheNextman made this suggestion for my issue; unfortunately this doesn’t seem to help in my case.)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search