From cd877660cd8094d81f2006bfbba93f9090123099 Mon Sep 17 00:00:00 2001 From: Abhishek Banthia <8280282+n0shake@users.noreply.github.com> Date: Sun, 7 Apr 2024 15:57:44 -0400 Subject: [PATCH] Switch to macOS 14 APIs. --- .../CalendarHandler.swift | 35 +++++++++++++++---- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/Clocker/Events and Reminders/CalendarHandler.swift b/Clocker/Events and Reminders/CalendarHandler.swift index 8182045..e824c7d 100644 --- a/Clocker/Events and Reminders/CalendarHandler.swift +++ b/Clocker/Events and Reminders/CalendarHandler.swift @@ -172,21 +172,42 @@ extension EventCenter { func initializeStoreIfNeccesary() { if eventStore == nil { eventStore = EKEventStore() + eventStore.reset() } } func requestAccess(to entity: EKEntityType, completionHandler: @escaping (_ granted: Bool) -> Void) { initializeStoreIfNeccesary() - - eventStore.requestAccess(to: entity) { [weak self] granted, _ in - - // On successful granting of calendar permission, we default to showing events from all calendars - if let self = self, entity == .event, granted { - self.saveDefaultIdentifiersList() + + if #available(macOS 14.0, *) { + eventStore.requestFullAccessToEvents { [weak self] granted, error in + // On successful granting of calendar permission, we default to showing events from all calendars + if let self = self, entity == .event, granted { + self.saveDefaultIdentifiersList() + } else if let requestError = error { + Logger.info("Unable to request events access due to \(requestError.localizedDescription)") + } else { + Logger.info("Request events access failed silently") + } + completionHandler(granted) } + } else { + eventStore.requestAccess(to: entity) { [weak self] granted, error in + + // On successful granting of calendar permission, we default to showing events from all calendars + if let self = self, entity == .event, granted { + self.saveDefaultIdentifiersList() + } else if let requestError = error { + Logger.info("Unable to request events access due to \(requestError.localizedDescription)") + } else { + Logger.info("Request events access failed silently") + } - completionHandler(granted) + completionHandler(granted) + } } + + } func filterEvents() {