[iOS] 1.4.0 - Apple Fitness Integration!

This commit is contained in:
2025-10-10 11:44:33 -06:00
parent ad8723b8fe
commit 790b7075c5
7 changed files with 279 additions and 10 deletions

View File

@@ -1,5 +1,6 @@
import Combine
import Foundation
import HealthKit
import SwiftUI
import UniformTypeIdentifiers
@@ -29,10 +30,9 @@ class ClimbingDataManager: ObservableObject {
private let decoder = JSONDecoder()
private var liveActivityObserver: NSObjectProtocol?
// Sync service for automatic syncing
let syncService = SyncService()
let healthKitService = HealthKitService.shared
// Published property to propagate sync state changes
@Published var isSyncing = false
private enum Keys {
@@ -336,6 +336,18 @@ class ClimbingDataManager: ObservableObject {
for: newSession, gymName: gym.name)
}
}
if healthKitService.isEnabled {
Task {
do {
try await healthKitService.startWorkout(
startDate: newSession.startTime ?? Date(),
sessionId: newSession.id)
} catch {
print("Failed to start HealthKit workout: \(error.localizedDescription)")
}
}
}
}
func endSession(_ sessionId: UUID) {
@@ -361,6 +373,17 @@ class ClimbingDataManager: ObservableObject {
Task {
await LiveActivityManager.shared.endLiveActivity()
}
if healthKitService.isEnabled {
Task {
do {
try await healthKitService.endWorkout(
endDate: completedSession.endTime ?? Date())
} catch {
print("Failed to end HealthKit workout: \(error.localizedDescription)")
}
}
}
}
}