Why are Google calendars not showing up in EKCalendarChooser on macOS in SwiftUI

Viewed 160

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.

2 Answers

I'm also having exact same problem. I do not have a solution to this... But I have tried to get the calendar's sources from Eventstore. And and I run my app on Mac, it lists all calendars including the ones from Google. So I guess somehow the EKCalendarChooser does not see calendars from Google. As אהרן אדלמן suggested, may be I have to crate my own calendar chooser interface with SwiftUI. But again, that's a lot of work compared to EKCalendarChooser which should just work.

Apple has just replied (June 2022) to my year-old bug report about this issue, and they claim that it is fixed in the macOS 13 beta. I'm unable to test and verify that at this time though.

Related