mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-18 14:54:46 +00:00
Restores first-use iOS authorization prompts for Contacts, Calendar, and Reminders by adding the missing usage descriptions, requesting access from `.notDetermined` in the service paths, and adding Settings Privacy & Access status/actions. Verification: - `plutil -lint apps/ios/Sources/Info.plist apps/ios/Tests/Info.plist apps/ios/ShareExtension/Info.plist apps/ios/ActivityWidget/Info.plist apps/ios/WatchApp/Info.plist apps/ios/WatchExtension/Info.plist` - `swiftformat --lint apps/ios/Sources/Permissions/PermissionRequestBridge.swift apps/ios/Sources/Contacts/ContactsService.swift apps/ios/Sources/Calendar/CalendarService.swift apps/ios/Sources/Reminders/RemindersService.swift apps/ios/Sources/Settings/PrivacyAccessSectionView.swift apps/ios/Sources/Settings/SettingsTab.swift apps/ios/Sources/Onboarding/GatewayOnboardingView.swift apps/shared/OpenClawKit/Sources/OpenClawKit/DeepLinks.swift --config config/swiftformat` - `swiftlint lint --config apps/ios/.swiftlint.yml apps/ios/Sources/Permissions/PermissionRequestBridge.swift apps/ios/Sources/Contacts/ContactsService.swift apps/ios/Sources/Calendar/CalendarService.swift apps/ios/Sources/Reminders/RemindersService.swift apps/ios/Sources/Settings/PrivacyAccessSectionView.swift apps/ios/Sources/Settings/SettingsTab.swift apps/ios/Sources/Onboarding/GatewayOnboardingView.swift apps/ios/Tests/PermissionRequestBridgeTests.swift` - `git diff --check origin/main...HEAD` - `rg '<<<<<<<|=======|>>>>>>>' CHANGELOG.md apps/ios apps/shared/OpenClawKit/Sources/OpenClawKit/DeepLinks.swift` - `pnpm ios:build` - `xcodebuild test -project apps/ios/OpenClaw.xcodeproj -scheme OpenClaw -destination 'platform=iOS Simulator,name=iPhone 17' -configuration Debug -only-testing:OpenClawTests/PermissionRequestBridgeTests` - Fresh-erased iPhone 17 simulator proof for Contacts denial/Open Settings, Calendar add-only/full-access upgrade, and Reminders authorization prompts. Not tested: physical device, or a paired gateway command invocation after onboarding.
151 lines
6.0 KiB
Swift
151 lines
6.0 KiB
Swift
import EventKit
|
|
import Foundation
|
|
import OpenClawKit
|
|
|
|
final class RemindersService: RemindersServicing {
|
|
func list(params: OpenClawRemindersListParams) async throws -> OpenClawRemindersListPayload {
|
|
let status = EKEventStore.authorizationStatus(for: .reminder)
|
|
let authorized: Bool = if status == .notDetermined || status == .writeOnly {
|
|
await Self.requestFullReminderAccess()
|
|
} else {
|
|
EventKitAuthorization.allowsRead(status: status)
|
|
}
|
|
guard authorized else {
|
|
throw NSError(domain: "Reminders", code: 1, userInfo: [
|
|
NSLocalizedDescriptionKey: "REMINDERS_PERMISSION_REQUIRED: grant Reminders permission",
|
|
])
|
|
}
|
|
|
|
let store = EKEventStore()
|
|
let limit = max(1, min(params.limit ?? 50, 500))
|
|
let statusFilter = params.status ?? .incomplete
|
|
|
|
let predicate = store.predicateForReminders(in: nil)
|
|
let payload: [OpenClawReminderPayload] = try await withCheckedThrowingContinuation { cont in
|
|
store.fetchReminders(matching: predicate) { items in
|
|
let formatter = ISO8601DateFormatter()
|
|
let filtered = (items ?? []).filter { reminder in
|
|
switch statusFilter {
|
|
case .all:
|
|
true
|
|
case .completed:
|
|
reminder.isCompleted
|
|
case .incomplete:
|
|
!reminder.isCompleted
|
|
}
|
|
}
|
|
let selected = Array(filtered.prefix(limit))
|
|
let payload = selected.map { reminder in
|
|
let due = reminder.dueDateComponents.flatMap { Calendar.current.date(from: $0) }
|
|
return OpenClawReminderPayload(
|
|
identifier: reminder.calendarItemIdentifier,
|
|
title: reminder.title,
|
|
dueISO: due.map { formatter.string(from: $0) },
|
|
completed: reminder.isCompleted,
|
|
listName: reminder.calendar.title)
|
|
}
|
|
cont.resume(returning: payload)
|
|
}
|
|
}
|
|
|
|
return OpenClawRemindersListPayload(reminders: payload)
|
|
}
|
|
|
|
func add(params: OpenClawRemindersAddParams) async throws -> OpenClawRemindersAddPayload {
|
|
let status = EKEventStore.authorizationStatus(for: .reminder)
|
|
let authorized: Bool = if status == .notDetermined {
|
|
await Self.requestFullReminderAccess()
|
|
} else {
|
|
EventKitAuthorization.allowsWrite(status: status)
|
|
}
|
|
guard authorized else {
|
|
throw NSError(domain: "Reminders", code: 2, userInfo: [
|
|
NSLocalizedDescriptionKey: "REMINDERS_PERMISSION_REQUIRED: grant Reminders permission",
|
|
])
|
|
}
|
|
|
|
let store = EKEventStore()
|
|
let title = params.title.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
guard !title.isEmpty else {
|
|
throw NSError(domain: "Reminders", code: 3, userInfo: [
|
|
NSLocalizedDescriptionKey: "REMINDERS_INVALID: title required",
|
|
])
|
|
}
|
|
|
|
let reminder = EKReminder(eventStore: store)
|
|
reminder.title = title
|
|
if let notes = params.notes?.trimmingCharacters(in: .whitespacesAndNewlines), !notes.isEmpty {
|
|
reminder.notes = notes
|
|
}
|
|
reminder.calendar = try Self.resolveList(
|
|
store: store,
|
|
listId: params.listId,
|
|
listName: params.listName)
|
|
|
|
if let dueISO = params.dueISO?.trimmingCharacters(in: .whitespacesAndNewlines), !dueISO.isEmpty {
|
|
let formatter = ISO8601DateFormatter()
|
|
guard let dueDate = formatter.date(from: dueISO) else {
|
|
throw NSError(domain: "Reminders", code: 4, userInfo: [
|
|
NSLocalizedDescriptionKey: "REMINDERS_INVALID: dueISO must be ISO-8601",
|
|
])
|
|
}
|
|
reminder.dueDateComponents = Calendar.current.dateComponents(
|
|
[.year, .month, .day, .hour, .minute, .second],
|
|
from: dueDate)
|
|
}
|
|
|
|
try store.save(reminder, commit: true)
|
|
|
|
let formatter = ISO8601DateFormatter()
|
|
let due = reminder.dueDateComponents.flatMap { Calendar.current.date(from: $0) }
|
|
let payload = OpenClawReminderPayload(
|
|
identifier: reminder.calendarItemIdentifier,
|
|
title: reminder.title,
|
|
dueISO: due.map { formatter.string(from: $0) },
|
|
completed: reminder.isCompleted,
|
|
listName: reminder.calendar.title)
|
|
|
|
return OpenClawRemindersAddPayload(reminder: payload)
|
|
}
|
|
|
|
private static func requestFullReminderAccess() async -> Bool {
|
|
await PermissionRequestBridge.awaitRequest { completion in
|
|
let store = EKEventStore()
|
|
store.requestFullAccessToReminders { granted, _ in
|
|
completion(granted)
|
|
}
|
|
}
|
|
}
|
|
|
|
private static func resolveList(
|
|
store: EKEventStore,
|
|
listId: String?,
|
|
listName: String?) throws -> EKCalendar
|
|
{
|
|
if let id = listId?.trimmingCharacters(in: .whitespacesAndNewlines), !id.isEmpty,
|
|
let calendar = store.calendar(withIdentifier: id)
|
|
{
|
|
return calendar
|
|
}
|
|
|
|
if let title = listName?.trimmingCharacters(in: .whitespacesAndNewlines), !title.isEmpty {
|
|
if let calendar = store.calendars(for: .reminder).first(where: {
|
|
$0.title.compare(title, options: [.caseInsensitive, .diacriticInsensitive]) == .orderedSame
|
|
}) {
|
|
return calendar
|
|
}
|
|
throw NSError(domain: "Reminders", code: 5, userInfo: [
|
|
NSLocalizedDescriptionKey: "REMINDERS_LIST_NOT_FOUND: no list named \(title)",
|
|
])
|
|
}
|
|
|
|
if let fallback = store.defaultCalendarForNewReminders() {
|
|
return fallback
|
|
}
|
|
|
|
throw NSError(domain: "Reminders", code: 6, userInfo: [
|
|
NSLocalizedDescriptionKey: "REMINDERS_LIST_NOT_FOUND: no default list",
|
|
])
|
|
}
|
|
}
|