Add weather feature with WeatherKit integration for mood entries
Fetch and display weather data (temp, condition, hi/lo, humidity) when users log a mood. Weather is stored as JSON on MoodEntryModel and shown as a card in EntryDetailView. Premium-gated with location permission prompt. Includes BGTask retry for failed fetches and full analytics. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -65,10 +65,11 @@ final class MoodLogger {
|
||||
|
||||
Self.logger.info("Applying side effects for mood \(mood.rawValue) on \(date)")
|
||||
|
||||
let hasAccess = !IAPManager.shared.shouldShowPaywall
|
||||
|
||||
// 1. Sync to HealthKit if enabled, requested, and user has full access
|
||||
if syncHealthKit {
|
||||
let healthKitEnabled = GroupUserDefaults.groupDefaults.bool(forKey: UserDefaultsStore.Keys.healthKitEnabled.rawValue)
|
||||
let hasAccess = !IAPManager.shared.shouldShowPaywall
|
||||
if healthKitEnabled && hasAccess {
|
||||
Task {
|
||||
try? await HealthKitManager.shared.saveMood(mood, for: date)
|
||||
@@ -101,6 +102,14 @@ final class MoodLogger {
|
||||
|
||||
// 8. Mark side effects as applied for this date
|
||||
markSideEffectsApplied(for: date)
|
||||
|
||||
// 9. Fetch weather if enabled and user has full access
|
||||
let weatherEnabled = GroupUserDefaults.groupDefaults.bool(forKey: UserDefaultsStore.Keys.weatherEnabled.rawValue)
|
||||
if weatherEnabled && hasAccess {
|
||||
Task {
|
||||
await WeatherManager.shared.fetchAndSaveWeather(for: date)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Delete a mood entry for a specific date with all associated cleanup.
|
||||
|
||||
Reference in New Issue
Block a user