I have universal App for iOS and MacOS on SwiftUI. I need to create reminder. I have a code that works on iOS:
import EventKit
func checkRemindersPermission() {
let eventStore = EKEventStore()
eventStore.requestAccess(to: EKEntityType.reminder, completion: { granted, error in
if granted {
createReminder()
}
})
}
func createReminder() {
let eventStore = EKEventStore()
let alarm = EKAlarm(absoluteDate: localDate)
let reminder = EKReminder(eventStore: eventStore)
reminder.title = reminderTitle
reminder.addAlarm(alarm)
reminder.calendar = eventStore.defaultCalendarForNewReminders()
do {
try eventStore.save(reminder, commit: true)
} catch {
}
}
In Info I have NSRemindersUsageDescription key. I see Reminder permission window on MacOS and iOS. I can permit access to Reminder in MacOS (I see this permission in Setting) But when I try to create Reminder on MacOS I got error:
[CADXPCProxyHelper] Received error from calaccessd connection: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service named com.apple.CalendarAgent was invalidated: failed at lookup with error 159 - Sandbox restriction." UserInfo={NSDebugDescription=The connection to service named com.apple.CalendarAgent was invalidated: failed at lookup with error 159 - Sandbox restriction.}. Attempting to call any reply handler.
[EventKit] Can't save reminder either because you have no access or you're trying to save using the legacy store, which is no longer supported
Error Domain=EKErrorDomain Code=29 "(null)"
Why this code works on iOS and nor work on MacOS?
As the documentation for
EKEventStorestates, sandboxed macOS apps must provide an extra entitlement that isn't needed on iOS, namely thecom.apple.security.personal-information.calendarsentitlement.For more info, see the EKEventStore docs.