3

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.

  • Maybe google events are from type reminder? – davidev Dec 16 '20 at 18:13
  • I doubt it. My iPhone thinks they’re events. – אהרן אדלמן Dec 16 '20 at 19:19
  • Did you ever resolve this? I am experiencing the same issue. – lukemmtt Jun 29 '21 at 16:07
  • 2
    Not really. I’ve found that EventKitUI and SwiftUI really don’t like each other. This has led me to increasingly replace EventKitUI view controllers with my own views, and EKCalendarChooser was the first of the view controllers to receive this treatment. This has benefits if one’s app creates a parallel system of events and event calendars which due to protocols can largely be treated identically, but there’s still a huge amount of work involved. – אהרן אדלמן Jul 01 '21 at 07:13
  • Thanks for posting this. I'm in a Swift/UIKit project right now, but running in on macOS 13, and planning on moving to SwiftUI. most account UI shows iCloud always-first, but the `EKCalendarChooser` puts "Google" accounts at the top of the sources list, over "iCloud". I assume this could be hard-coded by type, I've confirmed it wasn't simply the default names in a by-name sort. I've tested by renaming "google" to "Zoogle" and "Agoogle" (reboot required) – benc Jul 14 '23 at 19:52

2 Answers2

0

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.

Boon
  • 111
  • 1
  • 5
  • Just wanted to chime in and say that just this month I finally received a response to my bug report from apple, and they claim to have fixed this issue in an upcoming release of macOS. They wanted me to download the beta of macOS (not sure which one off the top of my head) to test and confirm the fix, but I’ve since built my own custom VC, so I have not tested their fix. I will update my answer accordingly with more details later. – lukemmtt Jun 29 '22 at 10:05
  • That's great news! I am also starting to build a SwiftUI-based calendar chooser. It's not too difficult in my opinion. Just quite a work to do. Thank you. I don't have a spare Mac so I cannot test either. – Boon Jun 29 '22 at 14:49
  • For what it’s worth, I have a UIKit-built calendar chooser I made that would be glad to share too. Best of luck regardless! – lukemmtt Jun 30 '22 at 15:05
  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/32121029) – Nol4635 Jul 01 '22 at 22:44
0

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.

lukemmtt
  • 476
  • 6
  • 15