
























@@ -4,15 +4,19 @@ import OpenClawKit
4455final class CalendarService: CalendarServicing {
66func events(params: OpenClawCalendarEventsParams) async throws -> OpenClawCalendarEventsPayload {
7-let store = EKEventStore()
87let status = EKEventStore.authorizationStatus(for: .event)
9-let authorized = EventKitAuthorization.allowsRead(status: status)
8+let authorized: Bool = if status == .notDetermined || status == .writeOnly {
9+await Self.requestFullEventAccess()
10+} else {
11+EventKitAuthorization.allowsRead(status: status)
12+}
1013guard authorized else {
1114throw NSError(domain: "Calendar", code: 1, userInfo: [
1215 NSLocalizedDescriptionKey: "CALENDAR_PERMISSION_REQUIRED: grant Calendar permission",
1316])
1417}
151819+let store = EKEventStore()
1620let (start, end) = Self.resolveRange(
1721 startISO: params.startISO,
1822 endISO: params.endISO)
@@ -37,15 +41,19 @@ final class CalendarService: CalendarServicing {
3741}
38423943func add(params: OpenClawCalendarAddParams) async throws -> OpenClawCalendarAddPayload {
40-let store = EKEventStore()
4144let status = EKEventStore.authorizationStatus(for: .event)
42-let authorized = EventKitAuthorization.allowsWrite(status: status)
45+let authorized: Bool = if status == .notDetermined {
46+await Self.requestWriteOnlyEventAccess()
47+} else {
48+EventKitAuthorization.allowsWrite(status: status)
49+}
4350guard authorized else {
4451throw NSError(domain: "Calendar", code: 2, userInfo: [
4552 NSLocalizedDescriptionKey: "CALENDAR_PERMISSION_REQUIRED: grant Calendar permission",
4653])
4754}
485556+let store = EKEventStore()
4957let title = params.title.trimmingCharacters(in: .whitespacesAndNewlines)
5058guard !title.isEmpty else {
5159throw NSError(domain: "Calendar", code: 3, userInfo: [
@@ -95,6 +103,24 @@ final class CalendarService: CalendarServicing {
95103return OpenClawCalendarAddPayload(event: payload)
96104}
97105106+private static func requestFullEventAccess() async -> Bool {
107+await PermissionRequestBridge.awaitRequest { completion in
108+let store = EKEventStore()
109+ store.requestFullAccessToEvents { granted, _ in
110+completion(granted)
111+}
112+}
113+}
114+115+private static func requestWriteOnlyEventAccess() async -> Bool {
116+await PermissionRequestBridge.awaitRequest { completion in
117+let store = EKEventStore()
118+ store.requestWriteOnlyAccessToEvents { granted, _ in
119+completion(granted)
120+}
121+}
122+}
123+98124private static func resolveCalendar(
99125 store: EKEventStore,
100126 calendarId: String?,
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。