Files
pulse-mobile/PulseWidget/KeychainService.swift
Daniil Klimov a07696bd55 fix: widgets use App Group shared UserDefaults instead of Keychain
- Widgets can't access app's Keychain (different sandbox)
- App writes data to shared UserDefaults (group.com.daniil.pulsehealth)
- Widgets read from shared UserDefaults — no API calls needed
- WidgetDataService: updates widget data + reloads timelines
- DashboardView: pushes habits/tasks data to widget after load
- HealthView: pushes health data to widget after load
- App Group capability added to both app and widget entitlements
- Widgets update every 15 minutes from cached data

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-06 14:47:26 +03:00

19 lines
818 B
Swift

import Foundation
// Widget reads data from shared UserDefaults (App Group), not Keychain
enum WidgetData {
static let suiteName = "group.com.daniil.pulsehealth"
static var shared: UserDefaults? {
UserDefaults(suiteName: suiteName)
}
static var habitsCompleted: Int { shared?.integer(forKey: "w_habits_completed") ?? 0 }
static var habitsTotal: Int { shared?.integer(forKey: "w_habits_total") ?? 0 }
static var tasksCount: Int { shared?.integer(forKey: "w_tasks_count") ?? 0 }
static var steps: Int { shared?.integer(forKey: "w_steps") ?? 0 }
static var sleep: Double { shared?.double(forKey: "w_sleep") ?? 0 }
static var heartRate: Int { shared?.integer(forKey: "w_heart_rate") ?? 0 }
static var readinessScore: Int { shared?.integer(forKey: "w_readiness") ?? 0 }
}