I have released a watchOS-specific application that retrieves data from the iPhone calendar app and displays it on the Apple Watch.
It uses the calendars function in EKEventStore to retrieve the list of calendars, but it seems that it sometimes fails to retrieve iCloud calendars.
Trouble is, this problem only occurs in a very few users‘ environments, the majority of other users’ environments are able to retrieve them without any problems, and I cannot reproduce it at all in my environment.
Local calendars and Google calendars seem to be retrieved without any problems.
Minimal example code:
import SwiftUI
import EventKit
struct ContentView: View {
let eventStore = EKEventStore()
@State var success: Bool = false
@State var calendarNames: [String] = [String]()
func request() async {
success = (try? await eventStore.requestFullAccessToEvents()) ?? false
}
func list() {
calendarNames = eventStore.calendars(for: .event).map { $0.title }
}
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Access: \(success.description)")
ScrollView {
ForEach(calendarNames, id: \.self) { name in
Text(name)
}
}
}
.onAppear {
Task {
await request()
list()
}
}
.padding()
}
}
I asked the user experiencing the problem to try restarting the iPhone and Apple Watch, reinstalling the app and re-pairing them, but there was no change.
I would appreciate any information you can provide.
Best regards.