How do I get data like move and exercise time from HealthKit
This is my current code -
It does not work
How can I improve this to get the values out of the HealthKit object
Code Block import SwiftUI import HealthKit struct Health: View { var body: some View { let healthStore = HKHealthStore() let objectTypes: Set<HKObjectType> = [ HKObjectType.activitySummaryType() ] healthStore.requestAuthorization(toShare: nil, read: objectTypes) { (success, error) in // Authorization request finished, hopefully the user allowed access! let calendar = Calendar.autoupdatingCurrent var dateComponents = calendar.dateComponents( [ .year, .month, .day ], from: Date() ) // This line is required to make the whole thing work dateComponents.calendar = calendar let predicate = HKQuery.predicateForActivitySummary(with: dateComponents) et; query = HKActivitySummaryQuery(predicate: predicate) { (query, summaries, error) in guard let summaries = summaries, summaries.count > 0 else { return } let sandUnit = HKUnit.count() let standHours = summary.appleStandHours.doubleValue(for: standUnit) } } } } struct Health_Previews: PreviewProvider { static var previews: some View { Health() } }
This is my current code -
It does not work
How can I improve this to get the values out of the HealthKit object