Problem with EKEventStore

Hi


Am having problems creating an EKEventStore to access the calendars.


To simplify the problem I created an OS X project in swift 4 with one button on the view. In the View controller I have imported EventKit. There is an @IBAction, as shown below, linked to the button. The sandbox is on with access to calendar checked.


@IBAction func testEK(_ sender: Any) {

let eventStore = EKEventStore.init()


}


When the button is clicked the following appears in the debug console area


2018-11-13 19:19:56.985235+0000 EKTest[6916:407014] CoreData: XPC: Unable to load metadata: Error Domain=NSCocoaErrorDomain Code=134070 "An error occurred in the persistent store." UserInfo={Problem=request failed, insufficient permission}

2018-11-13 19:19:56.985845+0000 EKTest[6916:407014] [error] error: -addPersistentStoreWithType:NSXPCStore configuration:(null) URL:file:///Users/jimgraham/Library/Calendars/Calendar%20Cache options:{

NSInferMappingModelAutomaticallyOption = 1;

NSMigratePersistentStoresAutomaticallyOption = 1;

NSPersistentHistoryTrackingKey = {

NSPersistentHistoryTrackingEntitiesToExclude = (

ChangeRequest

);

};

agentOrDaemon = 1;

serviceName = "com.apple.CalendarAgent.database";

} ... returned error Error Domain=NSCocoaErrorDomain Code=134070 "An error occurred in the persistent store." UserInfo={Problem=request failed, insufficient permission} with userInfo dictionary {

Problem = "request failed, insufficient permission";

}

CoreData: error: -addPersistentStoreWithType:NSXPCStore configuration:(null) URL:file:///Users/jimgraham/Library/Calendars/Calendar%20Cache options:{

NSInferMappingModelAutomaticallyOption = 1;

NSMigratePersistentStoresAutomaticallyOption = 1;

NSPersistentHistoryTrackingKey = {

NSPersistentHistoryTrackingEntitiesToExclude = (

ChangeRequest

);

};

agentOrDaemon = 1;

serviceName = "com.apple.CalendarAgent.database";

} ... returned error Error Domain=NSCocoaErrorDomain Code=134070 "An error occurred in the persistent store." UserInfo={Problem=request failed, insufficient permission} with userInfo dictionary {

Problem = "request failed, insufficient permission";

}


What is wrong and what do I need to do to create event store constant?

I'm having the exact same problem. Keep in mind an application needs to be entitled to access the calendar.

What's worse is that subsequent calls to store.requestAccess() don't prompt the user (which they should) but also don't result in any errors, however, access is NOT granted. I suspect this is a macOS bug...!?

Make sure to include the calendar usage description entry in your Info.plist. Without it, the user won't be prompted to grant access to calendar data.

<key>NSCalendarsUsageDescription</key>

<string>Description of why app needs access to the Calendar</string>


Unfortunately there are no useful errors emitted that would readily lead a developer to discover the underlying issue.

I'm not sure it's a bug, but this is happening to me - as of this writing the plist variable is "Privacy - Calendars Usage Description" and then you enter a string that goes to the prompt for the user. Since I am using XCode to run the program, perhaps this is causing the prompt to 'fail' - either way, I can't get this to work and I'm not going to code prompts either...

FYI- this key doesn't exist anymore - it's: "Privacy - Calendars Usage Description"

Problem with EKEventStore
 
 
Q