Skip to content

Commit

Permalink
[Fix] #252 - 00시에 AppGroup의 dailyMission 업데이트 되도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
yungu0010 committed Jun 26, 2024
1 parent 048e70f commit 6bb2a0b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion iOS-NOTTODO/Widget-NOTTODO/Provider/MissionProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct Provider: AppIntentTimelineProvider {
@AppStorage("quote", store: UserDefaults.shared) var quote: String = ""

func placeholder(in context: Context) -> SimpleEntry {
SimpleEntry(todayMission: [], quote: "")
SimpleEntry(todayMission: [], quote: quote)
}

func snapshot(for configuration: ConfigurationAppIntent, in context: Context) async -> SimpleEntry {
Expand All @@ -34,6 +34,7 @@ struct Provider: AppIntentTimelineProvider {

if now == midnightToday {
try await getQuote()
try await getDailyMission(date: Formatter.dateFormatterString(format: nil, date: now))
}

guard let decodedData = try? JSONDecoder().decode([DailyMissionResponseDTO].self, from: sharedData) else {
Expand All @@ -52,4 +53,9 @@ struct Provider: AppIntentTimelineProvider {
let quoteResponse = try await WidgetService.shared.fetchWiseSaying()
quote = quoteResponse.description + " - " + quoteResponse.author
}

private func getDailyMission(date: String) async throws {
let dailyMission = try await WidgetService.shared.fetchDailyMissoin(date: date)
UserDefaults.shared?.setSharedCustomArray(dailyMission, forKey: "dailyMission")
}
}

0 comments on commit 6bb2a0b

Please sign in to comment.