mycode/myApp/HaruDanim/IOS/Core/AppRefresh.swift
songyc macbook 6b5e1dc20a fix(main): 새로고침 버튼 프리미엄 판정을 RefreshButton body 안으로 이동
- .toolbar { if PremiumManager.shared.isPremium } 조건은 @Observable 변경 시
  재평가가 보장되지 않아, 실행 중 프리미엄 전환(설정 테스트 토글·구매) 후
  버튼이 앱 재시작 전까지 나타나지 않는 실기기 결함 (아이폰·아이패드·맥 공통)
- ToolbarItem은 무조건 두고 RefreshButton body에서 판정 — View body는
  관찰 추적이 확실 (같은 body의 isRefreshing 전환이 검증된 패턴)
- 검증: Debug·Store 빌드, 무료(버튼 없음)/프리미엄(버튼 표시) 아이폰·아이패드 캡처

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-23 21:54:11 +09:00

77 lines
3.3 KiB
Swift
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// AppRefresh.swift
// Haru_Danim
//
// ( )
// - iCloud ,
// . token identity @Query
// ( , ).
// - (CloudSyncMonitor) ·· .
// .
// " " , CloudKit
// API . (UIBackgroundModes:
// remote-notification, IOS/Info.plist)
// / ( ).
//
import Foundation
import Observation
import SwiftData
import WidgetKit
@MainActor
@Observable
final class AppRefresh {
static let shared = AppRefresh()
/// RootNavigationView .id
private(set) var token = UUID()
private(set) var isRefreshing = false
func refreshNow() {
guard !isRefreshing else { return }
isRefreshing = true
token = UUID()
Task { @MainActor in
//
LiveActivityManager.sync(context: DataStore.shared.mainContext)
WidgetCenter.shared.reloadAllTimelines()
WatchSyncManager.shared.pushSnapshot()
//
try? await Task.sleep(for: .milliseconds(700))
isRefreshing = false
}
}
}
// MARK: - ( )
import SwiftUI
/// .
/// (iCloud ·/ )
/// .
/// body MainView .toolbar { if ... }
/// @Observable , ( ·)
/// (2026-07-23)
struct RefreshButton: View {
private let refresh = AppRefresh.shared
var body: some View {
if PremiumManager.shared.isPremium {
Button {
refresh.refreshNow()
} label: {
if refresh.isRefreshing {
ProgressView()
} else {
Image(systemName: "arrow.clockwise")
}
}
.disabled(refresh.isRefreshing)
.accessibilityLabel(Text("새로고침"))
.accessibilityHint(Text("다른 기기에서 바뀐 내용을 다시 불러오고 위젯도 갱신해요"))
}
}
}