everyone.
What I am doing: I am writing a program doing various date and time-related things in SwiftUI for iOS and macOS. The current version of the UI is written in SwiftUI. Since my program can use EventKit (the engine behind events in Calendar.app) and EventKitUI does not yet have a SwiftUI equivalent, I have wrappers for EventKitUI view controllers.
What is going wrong: I have (among other things) a wrapper around EKCalendarChooser to allow the user to select which external event calendars he/she wants my program to use. This works fine on iOS. On macOS, however, event calendars in my Google account do not appear, even though my program shows the events themselves in macOS. Local, iCloud, and “other” event calendars do appear.
My code:
import EventKitUI
import SwiftUI
struct ASAEKCalendarChooserView: UIViewControllerRepresentable {
func makeCoordinator() -> Coordinator {
return Coordinator(self)
}
@Environment(\.presentationMode) var presentationMode
var externalEventManager = ASAExternalEventManager.shared
var calendars: Set<EKCalendar>? = ASAExternalEventManager.shared.calendarSet
func makeUIViewController(context: UIViewControllerRepresentableContext<ASAEKCalendarChooserView>) -> UINavigationController {
let chooser = EKCalendarChooser(selectionStyle: .multiple, displayStyle: .allCalendars, entityType: .event, eventStore: externalEventManager.eventStore)
chooser.selectedCalendars = calendars ?? []
chooser.delegate = context.coordinator
chooser.showsDoneButton = true
chooser.showsCancelButton = true
return UINavigationController(rootViewController: chooser)
}
func updateUIViewController(_ uiViewController: UINavigationController, context: UIViewControllerRepresentableContext<ASAEKCalendarChooserView>) {
}
class Coordinator: NSObject, UINavigationControllerDelegate, EKCalendarChooserDelegate {
let parent: ASAEKCalendarChooserView
init(_ parent: ASAEKCalendarChooserView) {
self.parent = parent
}
func calendarChooserDidFinish(_ calendarChooser: EKCalendarChooser) {
debugPrint(#file, #function, calendarChooser)
let calendars = calendarChooser.selectedCalendars
parent.externalEventManager.calendars = Array(calendars)
ASAUserData.shared().savePreferences(code: .events)
parent.presentationMode.wrappedValue.dismiss()
}
func calendarChooserDidCancel(_ calendarChooser: EKCalendarChooser) {
debugPrint(#file, #function, calendarChooser)
parent.presentationMode.wrappedValue.dismiss()
}
}
}
Note: ASAExternalEventManager is a class of mine to make dealing with EKEventStore easier.
Also: The “missing” event calendars show up in Calendar.app, both in macOS and iOS.
Does anyone have any idea why I am having this problem? I do not understand why the same code running on two devices using the same accounts is giving two noticeably different results.
Thanks in advance for any help anyone can provide.