为什么谷歌日历没有出现在SwiftUI中macOS上的EKCalendarChooser中



每个人。

我正在做的事情:我正在写一个程序,在iOS和macOS的SwiftUI中做各种与日期和时间相关的事情。UI的当前版本是用SwiftUI编写的。由于我的程序可以使用EventKit(Calendar.app中事件背后的引擎(,而EventKitUI还没有SwiftUI等效程序,因此我有EventKitUI视图控制器的包装器。

出了什么问题:我有一个围绕EKCalendarChooser的包装器,允许用户选择他/她希望我的程序使用哪些外部事件日历。这在iOS上运行良好。然而,在macOS上,我的谷歌帐户中的事件日历不会出现,尽管我的程序在macOS中显示了事件本身。本地、iCloud和"其他"事件日历确实会出现。

我的代码:

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()
}
}
}

注意:ASAExternalEventManager是我的一个类,它使处理EKEventStore变得更容易。

此外:"丢失"的事件日历显示在Calendar.app中,无论是在macOS还是iOS中。

有人知道我为什么会有这个问题吗?我不明白为什么在使用相同帐户的两台设备上运行的相同代码会产生两个明显不同的结果。

提前感谢任何人能提供的帮助。

我也遇到了完全相同的问题。我对此没有解决方案。。。但我已经尝试过从Eventstore获取日历的来源。我在Mac上运行我的应用程序,它列出了所有日历,包括谷歌的日历。所以我想EKCalendarChooser不知怎么看不到谷歌的日历。正如前所述,我可能不得不用SwiftUI自带日历选择器界面。但同样,与EKCalendarChooser相比,这是一项艰巨的工作,它应该只是工作。

苹果刚刚(2022年6月(回复了我一年前关于这个问题的错误报告,他们声称它在macOS 13测试版中得到了修复。不过目前我还无法对此进行测试和验证。

最新更新