Post not yet marked as solved
Post marked as unsolved with 2 replies, 944 views
Hi, I have a Swift 5 project which accesses the user Calendar on a Mac Mojave via EKEventstore. I use the following code to initializes the access to the calendar:var eventStore = EKEventstore()
func requestAccessToCalendar() {
eventStore.requestAccess(to: .event, completion: {
granted, error in
})
}
func loadCalendars() {
calendars = eventStore.calendars(for: .event)
}
let ekstatus = EKEventStore.authorizationStatus(for: EKEntityType.event)
switch (ekstatus) {
case EKAuthorizationStatus.notDetermined:
// This happens on first-run
requestAccessToCalendar()
case EKAuthorizationStatus.authorized:
// Things are in line with being able to fetch all client events in the next period upfront
loadCalendars()
getFutureVisits()
case EKAuthorizationStatus.restricted, EKAuthorizationStatus.denied:
// We need to help them give us permission
dialogOK("access denied")
@unknown default:
dialogOK("general access problem")
}On the first run, the app logs permission problems in the XCode console, then asks the user to grant permission, which is granted but no calendar entries found. Any subsequent runs work fine as expected. The errors are reported directly when the eventStore instance is initialized. II've tried several options with lazy vars or constants, but all resulted in the same problem. The Apple developper documents unfortunatly show outdated ways to init the EKEventstore and I found nowhere a solution which works with Swift 5 and OS 10.14 Did anyone succeed to have the instance initiated the first time without errors? I would appreciate a code sample.