- HealthWorkoutType(WorkoutConfig 필드, 워치 자동 동기화) — 폰·워치 저장 모두 반영 - 설정 → 애플 건강에 '운동 유형' 피커, 푸터·도움말 문구 유형 중립으로 갱신 - 신규 문자열 번역(en/ja), 옛 문구 stale 2건 정리 — 전 카탈로그 missing·stale 0 - 하루 다님 연계 조사 결과 CLAUDE.md 기록(종목 다짐·타임테이블=자동 집계, 운동 시간 지표=워치 실행분만 운동 링 경유 반영) - 검증: Debug·Release·워치 빌드 그린, 설정 화면 QA Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UPmp29DQHY6Ahfss5SRopT
60 lines
2.4 KiB
Swift
60 lines
2.4 KiB
Swift
//
|
|
// HealthKitCalls.swift
|
|
// Keging
|
|
//
|
|
// HealthKit completion API의 async 래퍼 — iOS(사후 빌더)·워치(라이브 빌더) 공용
|
|
//
|
|
|
|
import HealthKit
|
|
|
|
extension HealthWorkoutType {
|
|
var activityType: HKWorkoutActivityType {
|
|
switch self {
|
|
case .other: .other
|
|
case .coreTraining: .coreTraining
|
|
}
|
|
}
|
|
}
|
|
|
|
nonisolated enum HealthKitCalls {
|
|
static func beginCollection(_ builder: HKWorkoutBuilder, at date: Date) async throws {
|
|
try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, Error>) in
|
|
builder.beginCollection(withStart: date) { _, error in
|
|
if let error { continuation.resume(throwing: error) } else { continuation.resume() }
|
|
}
|
|
}
|
|
}
|
|
|
|
static func endCollection(_ builder: HKWorkoutBuilder, at date: Date) async throws {
|
|
try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, Error>) in
|
|
builder.endCollection(withEnd: date) { _, error in
|
|
if let error { continuation.resume(throwing: error) } else { continuation.resume() }
|
|
}
|
|
}
|
|
}
|
|
|
|
static func finishWorkout(_ builder: HKWorkoutBuilder) async throws -> HKWorkout? {
|
|
try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<HKWorkout?, Error>) in
|
|
builder.finishWorkout { workout, error in
|
|
if let error { continuation.resume(throwing: error) } else { continuation.resume(returning: workout) }
|
|
}
|
|
}
|
|
}
|
|
|
|
/// 운동 강도(1~10) 샘플을 운동에 연결 — 애플 운동 앱의 강도 기록과 같은 데이터
|
|
@available(iOS 18.0, watchOS 11.0, *)
|
|
static func relateEffort(store: HKHealthStore, workout: HKWorkout, score: Int) async throws {
|
|
let sample = HKQuantitySample(
|
|
type: HKQuantityType(.workoutEffortScore),
|
|
quantity: HKQuantity(unit: .appleEffortScore(), doubleValue: Double(min(max(score, 1), 10))),
|
|
start: workout.startDate,
|
|
end: workout.endDate
|
|
)
|
|
try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, Error>) in
|
|
store.relateWorkoutEffortSample(sample, with: workout, activity: nil) { _, error in
|
|
if let error { continuation.resume(throwing: error) } else { continuation.resume() }
|
|
}
|
|
}
|
|
}
|
|
}
|