라이브 액티비티(다이내믹 아일랜드) 워치 연동:
- 워치 실행 명령이 세션 활성화 전이거나 sendMessage 실패 시 유실되던 문제를
transferUserInfo 큐 폴백으로 보강 (iPhone didReceiveUserInfo 수신 처리 추가)
- 큐로 지연 도착한 실행 명령이 엉뚱한 토글을 일으키지 않도록 5분 유효 시간 부여
- 백그라운드에서 Live Activity 시작이 거부되면 pendingStartRetry로 기억했다가
앱 포그라운드 복귀(scenePhase active) 시 재시도 + DB 상태 재동기화
- WatchSync 진단용 os_log(notice) 추가, DEBUG -autoRunFirstAction 검증 훅 추가
- 시뮬레이터 검증: 워치 시작 → 아이폰 세션 시작 + 다이내믹 아일랜드 생성,
워치 종료 → 세션 종료 + 아일랜드 소멸 확인 (큐 폴백 채널은 시뮬레이터
transferUserInfo 한계로 실기기 확인 필요)
앱 이름 전역 띄어쓰기 ('하루다님' → '하루 다님'):
- pbxproj CFBundleDisplayName 6곳, InfoPlist.xcstrings 3개(ko), 스플래시(ContentView),
워치 내비게이션 타이틀, 컴플리케이션 문구, 문자열 카탈로그 키 일괄 변경
- 워치 카탈로그 영문 값 HaruDanim → Haru Danim 통일
통계 위젯 X축 라벨 겹침 방지:
- 날짜 축 포인트가 7개를 초과하면(한 달·일별 등) 라벨을 숨기고 눈금만 표시
위젯 설정 '선택 안 함' 옵션:
- Action/Goal/Quest 엔티티에 zero-UUID 센티널 추가, 제안 목록 최상단 노출
- 2·3번째 슬롯 선택을 되돌릴 수 있고, 위젯 조회 단계에서 자연스럽게 걸러짐
- ko/en/ja 번역 추가 (None / 選択しない)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013yKDMhuF39GVYy3FMcGHh7
88 lines
3.4 KiB
Swift
88 lines
3.4 KiB
Swift
//
|
|
// LiveActivityManager.swift
|
|
// Haru_Danim
|
|
//
|
|
// 추적 상태를 다이나믹 아일랜드/잠금화면 Live Activity에 반영 (CLAUDE.md §4.1, §4.2)
|
|
//
|
|
|
|
import Foundation
|
|
import ActivityKit
|
|
import SwiftData
|
|
|
|
enum LiveActivityManager {
|
|
/// 백그라운드(워치 명령으로 깨어난 상태 등)에서는 시스템이 Live Activity '시작'을
|
|
/// 허용하지 않으므로, 실패를 기억해 두고 앱이 포그라운드로 돌아올 때 재시도한다
|
|
static var pendingStartRetry = false
|
|
|
|
/// 현재 진행 중인 세션들을 읽어 Live Activity를 시작/갱신/종료한다.
|
|
/// 세션 시작·종료·수정 후마다 호출.
|
|
static func sync(context: ModelContext) {
|
|
guard ActivityAuthorizationInfo().areActivitiesEnabled else { return }
|
|
|
|
let descriptor = FetchDescriptor<TimeSession>(
|
|
predicate: #Predicate { $0.endAt == nil },
|
|
sortBy: [SortDescriptor(\.startAt, order: .forward)]
|
|
)
|
|
let running = (try? context.fetch(descriptor)) ?? []
|
|
|
|
let mode = LiveActivityMode(
|
|
rawValue: AppGroup.defaults.string(forKey: SettingsKeys.liveActivityMode)
|
|
?? UserDefaults.standard.string(forKey: SettingsKeys.liveActivityMode) ?? ""
|
|
) ?? .latest
|
|
let representative = mode == .earliest ? running.first : running.last
|
|
|
|
guard let representative, let action = representative.action else {
|
|
pendingStartRetry = false
|
|
endAll()
|
|
return
|
|
}
|
|
|
|
let state = TrackingActivityAttributes.ContentState(
|
|
actionName: action.name,
|
|
symbolName: action.symbolName,
|
|
colorHex: action.sortedTags.first?.colorHex ?? "#2F6B4F",
|
|
startedAt: representative.startAt,
|
|
extraCount: max(running.count - 1, 0)
|
|
)
|
|
let content = ActivityContent(state: state, staleDate: nil)
|
|
|
|
Task {
|
|
let activities = Activity<TrackingActivityAttributes>.activities
|
|
if let activity = activities.first {
|
|
await activity.update(content)
|
|
pendingStartRetry = false
|
|
// 혹시 중복 생성된 것이 있으면 정리
|
|
for extra in activities.dropFirst() {
|
|
await extra.end(nil, dismissalPolicy: .immediate)
|
|
}
|
|
} else {
|
|
do {
|
|
_ = try Activity<TrackingActivityAttributes>.request(
|
|
attributes: TrackingActivityAttributes(),
|
|
content: content
|
|
)
|
|
pendingStartRetry = false
|
|
} catch {
|
|
// 워치 명령 등 백그라운드 컨텍스트에서는 시작이 거부된다(visibility)
|
|
// → 포그라운드 복귀 시 syncIfRetryNeeded가 다시 시도
|
|
pendingStartRetry = true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// 앱이 포그라운드로 돌아왔을 때, 백그라운드에서 거부됐던 시작을 재시도
|
|
static func syncIfRetryNeeded(context: ModelContext) {
|
|
guard pendingStartRetry else { return }
|
|
sync(context: context)
|
|
}
|
|
|
|
static func endAll() {
|
|
Task {
|
|
for activity in Activity<TrackingActivityAttributes>.activities {
|
|
await activity.end(nil, dismissalPolicy: .immediate)
|
|
}
|
|
}
|
|
}
|
|
}
|