This commit is contained in:
Trey t
2023-08-16 00:16:38 -05:00
parent c0fdca9996
commit b501f66bf3
10 changed files with 234 additions and 81 deletions

View File

@@ -7,6 +7,7 @@
import Foundation
import SwiftUI
import HealthKit
enum MainViewTypes: Int, CaseIterable {
case AllWorkout = 0
@@ -27,7 +28,7 @@ struct AllWorkoutsView: View {
@State var isUpdating = false
@State var workouts: [Workout]?
@State var uniqueWorkoutUsers: [RegisteredUser]?
let healthStore = HKHealthStore()
var bridgeModule = BridgeModule.shared
@State public var needsUpdating: Bool = true
@@ -88,6 +89,7 @@ struct AllWorkoutsView: View {
}
}.onAppear{
// UserStore.shared.logout()
authorizeHealthKit()
maybeUpdateShit()
}
.sheet(item: $selectedWorkout) { item in
@@ -178,6 +180,21 @@ struct AllWorkoutsView: View {
showLoginView = true
}
}
func authorizeHealthKit() {
let healthKitTypes: Set = [
HKObjectType.quantityType(forIdentifier: .heartRate)!,
HKObjectType.quantityType(forIdentifier: .activeEnergyBurned)!,
HKObjectType.quantityType(forIdentifier: .oxygenSaturation)!,
HKQuantityType.workoutType()
]
healthStore.requestAuthorization(toShare: healthKitTypes, read: healthKitTypes) { (succ, error) in
if !succ {
fatalError("Error requesting authorization from health store: \(String(describing: error)))")
}
}
}
}
struct AllWorkoutsView_Previews: PreviewProvider {