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:
@@ -10,6 +10,7 @@ import BackgroundTasks
|
||||
|
||||
class BGTask {
|
||||
static let updateDBMissingID = "com.88oakapps.reflect.dbUpdateMissing"
|
||||
static let weatherRetryID = "com.88oakapps.reflect.weatherRetry"
|
||||
|
||||
@MainActor
|
||||
class func runFillInMissingDatesTask(task: BGProcessingTask) {
|
||||
@@ -27,6 +28,33 @@ class BGTask {
|
||||
task.setTaskCompleted(success: true)
|
||||
}
|
||||
|
||||
@MainActor
|
||||
class func runWeatherRetryTask(task: BGProcessingTask) {
|
||||
BGTask.scheduleWeatherRetry()
|
||||
|
||||
task.expirationHandler = {
|
||||
task.setTaskCompleted(success: false)
|
||||
}
|
||||
|
||||
Task {
|
||||
await WeatherManager.shared.retryPendingWeatherFetches()
|
||||
task.setTaskCompleted(success: true)
|
||||
}
|
||||
}
|
||||
|
||||
class func scheduleWeatherRetry() {
|
||||
let request = BGProcessingTaskRequest(identifier: BGTask.weatherRetryID)
|
||||
request.requiresNetworkConnectivity = true
|
||||
request.requiresExternalPower = false
|
||||
request.earliestBeginDate = Date(timeIntervalSinceNow: 15 * 60)
|
||||
|
||||
do {
|
||||
try BGTaskScheduler.shared.submit(request)
|
||||
} catch {
|
||||
print("Could not schedule weather retry: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
class func scheduleBackgroundProcessing() {
|
||||
let request = BGProcessingTaskRequest(identifier: BGTask.updateDBMissingID)
|
||||
request.requiresNetworkConnectivity = false
|
||||
|
||||
Reference in New Issue
Block a user