// // WatchDelegate.swift // Werkout_watch Watch App // // Created by Trey Tartt on 7/1/24. // import WatchKit import HealthKit import os class WatchDelegate: NSObject, WKApplicationDelegate { private let logger = Logger(subsystem: "com.werkout.watch", category: "lifecycle") func applicationDidFinishLaunching() { authorizeHealthKit() } func applicationDidBecomeActive() { } func applicationWillResignActive() { } func handle(_ workoutConfiguration: HKWorkoutConfiguration) { // WatchWorkout.shared.startWorkout() } func authorizeHealthKit() { guard let heartRateType = HKObjectType.quantityType(forIdentifier: .heartRate), let activeEnergyType = HKObjectType.quantityType(forIdentifier: .activeEnergyBurned), let oxygenSaturationType = HKObjectType.quantityType(forIdentifier: .oxygenSaturation) else { logger.error("Missing required HealthKit quantity types during authorization") return } let healthKitTypes: Set = [ heartRateType, activeEnergyType, oxygenSaturationType, HKObjectType.activitySummaryType(), HKQuantityType.workoutType() ] HKHealthStore().requestAuthorization(toShare: nil, read: healthKitTypes) { (succ, error) in if !succ { self.logger.error("HealthKit authorization failed: \(String(describing: error), privacy: .public)") } } } }