Health & Fitness

RSS for tag

Explore the technical aspects of health and fitness features, including sensor data acquisition, health data processing, and integration with the HealthKit framework.

Health & Fitness Documentation

Post

Replies

Boosts

Views

Activity

How to get Apple Watch to send workout session data to my fitness app instantly
I am working with Apple HealthKit, and I need to add functionality to my app that allows a user's Apple Watch to automatically send the relevant data for their workout session (e.g. vo2 max, start timestamp, end timestamp, heartbeat, duration etc) as soon as they end their workout. This would need to work for any type of workout they do. E.g. if they are doing a running session, when they end their workout my app needs to receive the data for that running session almost instantly. I know that enableBackgroundDelivery allows my app to listen to changes in Apple Health in the background, but I'm not sure which method in HealthKit will allow me to implement the above use case. Does anyone have any pointers? I just want to know what methods in HealthKit will allow me to achieve this.
1
0
662
Sep ’23
Bug in tutorial concerning displayName?
Hi there, Thanks for the great tutorial for WorkoutKit, that can be found here: https://developer.apple.com/videos/play/wwdc2023/10016/ In my view Text(scheduledWorkout.plan.workout.activity.displayName) in SamplePlannerView.swift (the main view) does not show the correct string. For example for the running workout, it should show: "New Running Workout". This string is set in WorkoutStore.swift. However, it shows "Outdoor Running", which is the type of workout but not the display name that was given to it. Best regards, Patrick
0
0
485
Sep ’23
Apple Health Kit
We have an app that reads data from the Apple Health Kit that is about 5 years old and we stopped receiving data from the app. While investigate why it quit working we are seeing some messages in the console log when we plug a phone into a mac that we are trying to get clarification on. We are seeing from the log: healthd 'STARTING: com.apple.healthkit.background-delivery.:<thread?>' followed by a: dasd 'COMPLETED com.apple.healthkit.background-delivery.:<thread?> at priority 30 then a dasd 'NO LONGER RUNNING com.apple.healthkit.background-delivery.:<thread?> ... Tasks running in the group [com.apple.dash.default] are 1! I was looking for some clarification on what these messages mean. Do they mean that our app was started and that the process completed successfully or, is it a warning saying that something abnormal happened. Also, I'm coming up short on documentation when I google for these messages. Is there a repository out there to help me make sense of what I'm seeing? Thanks for any insight!
0
0
454
Sep ’23
cyclingSpeed is 0
Hi, I am running the "Building a multidevice workout app" sample: https://developer.apple.com/documentation/healthkit/workouts_and_activity_rings/building_a_multidevice_workout_app I do not get any values for the .cyclingSpeed Value? Is this correct or should there be any value while moving around? Also i wonder if i can get the GPS values like altimeter or location from the HKWorkoutSession? Thanks
1
0
582
Sep ’23
Crash on fetching health kit data
I am receiving the following crash when trying to query data from health kit. It seems to be complaining about end date being before start date however with the values I am passing in that is not possible. Also I tried to purposefully pass in end dates before start date and I still was not able to reproduce this crash. I have attached my code snippet and the crash logs here. Please Help :( self.statisticfetcher( type: HKObjectType.quantityType(forIdentifier: .bodyMass), options: .discreteAverage, metricType: .bodyWeight, statsHandler: { stats in if let quantity = stats.averageQuantity() { ... } return nil }) private func statisticfetcher( type: HKQuantityType?, options: HKStatisticsOptions, metricType: HealthMetricType, statsHandler: @escaping (HKStatistics) -> BASchema.HealthDataEntryInput?, resultHandler: ((HKStatisticsCollection?, Date, Date, Error?) -> Void)? = nil) { let res = getStartEndDate() let endDate = res.endDate let startDate = res.startDate guard let type = type else { return } let query = HKStatisticsCollectionQuery(quantityType: type, quantitySamplePredicate: nil, options: options, anchorDate: startDate, intervalComponents: DateComponents(day: 1)) let defaultResultHandler: (HKStatisticsCollection?, Date, Date, Error?) -> Void = { statCollection, startDate, endDate, error in if let error = error { return } guard let statCollection = statCollection else { return } statCollection.enumerateStatistics(from: startDate, to: endDate) { stats, _ in ... } } let resultHandler = resultHandler ?? defaultResultHandler query.initialResultsHandler = { _, statCollection, error in resultHandler(statCollection, startDate, endDate, error) } query.statisticsUpdateHandler = { _, _, statCollection, error in resultHandler(statCollection, startDate, endDate, error) } self.store.execute(query) self.subscribeToBackgroundDelivery(type: type) } private func subscribeToBackgroundDelivery(type: HKObjectType) { store.enableBackgroundDelivery(for: type, frequency: .immediate) { success, error in if(error != nil && !success) { print("Background Delivery for \(type) Failed!") } } }``` Fatal Exception: NSInternalInconsistencyException 0 CoreFoundation 0x9cb4 __exceptionPreprocess 1 libobjc.A.dylib 0x183d0 objc_exception_throw 2 Foundation 0x4e156c _userInfoForFileAndLine 3 HealthKit 0xe0d2c -[HKDateInterval initWithStartDate:endDate:] 4 HealthKit 0xc7a5c -[NSDateComponents(HealthKit) hk_dateIntervalForDate:anchorDate:outIndex:] 5 HealthKit 0x1a0f98 -[HKStatisticsCollection _statisticsDateIntervalAndIndex:forDate:] 6 HealthKit 0x1a0420 -[HKStatisticsCollection _insertStatistics:] 7 HealthKit 0x1a059c -[HKStatisticsCollection _resetStatistics:] 8 HealthKit 0x19efc8 -[HKStatisticsCollectionQuery _queue_deliverResetStatisticsObjects:forQuery:] 9 HealthKit 0x19e8bc __98-[HKStatisticsCollectionQuery client_deliverStatisticsBatch:resetStatistics:isFinal:anchor:query:]_block_invoke 10 libdispatch.dylib 0x2320 _dispatch_call_block_and_release 11 libdispatch.dylib 0x3eac _dispatch_client_callout 12 libdispatch.dylib 0xb534 _dispatch_lane_serial_drain 13 libdispatch.dylib 0xc0d8 _dispatch_lane_invoke 14 libdispatch.dylib 0x16cdc _dispatch_workloop_worker_thread 15 libsystem_pthread.dylib 0xddc _pthread_wqthread 16 libsystem_pthread.dylib 0xb7c start_wqthread
4
0
941
May ’23
Would This Work? (Importing Medical Records)
So almost every EPIC customer is now at a version that would allow their medical records to be imported, many of them just haven't filled out the Apple form to list their organization. EPIC does publish a list of the FHIR endpoints for all of these customers though. Functionally it should be possible to write an app that authenticates the user to their provider, and downloads the FHIR data from the API, and then pushes it into Apple Health. The two things I'm not clear on though are: Are the Medical Records available to write to from an app, or is it only available through organizations registered through Apple using their UI? Would Apple consider this a replication of their functionality as far as App Store T's & C's go?
1
0
417
Aug ’23
Headphone accommodation with audiogram
Hi, i am developing an app to enter audiogram data to Apple HealthKit and i want to have a little more information about Apple‘s headphone accommodation. is there any information about how the accommodation exactly works? Which filters will be applied in the background? How are the filter coefficients created etc.? Is there any access to the resulting eq curve? Is there also dynamic compression used in a certain way? Kind regards, Tom
0
0
332
Aug ’23
HKLiveWorkoutBuilderDelegate not updating activeEnergyBurned HKQuantityType in watchOS 9.6.1(20U80)
The "func workoutBuilder(_ workoutBuilder: HKLiveWorkoutBuilder, didCollectDataOf collectedTypes: Set)" function from the "HKLiveWorkoutBuilderDelegate" is not updating data from "HKQuantityType.quantityType(forIdentifier: .activeEnergyBurned)" in a workout session. My app is using the same code as before and it stopped working since I updated my watch to the version 9.6.1(20U80). I am using Xcode 14.3.1 (14E300c). Is there any solution to address this matter?
0
0
374
Aug ’23
Problem with Sharing in Fitness app
Hello, I use iPhone 14 Pro with iOS 17 Beta, my girlfriend use iPhone 13 with newest iOS 16. We used to use Fitness application to share our daily activity (steps, kcals etc.) Unfortunately last time our activity progress doesn't shows properly. In my phone I have 1000 steps for example, my gf see 0 steps. The same was at I was on iOS 16. Removing and invitating again doesn't help. What can we check? Thanks in advance :)
0
0
383
Aug ’23
Getting sharingDenied when trying to check for access to activitySummaryType
So, I've wrote the following code; let status = healthStore.authorizationStatus(for: .activitySummaryType()) switch status { case .notDetermined: return false case .sharingDenied: return false case .sharingAuthorized: return true @unknown default: return false } And it is hitting the .sharingDenied case. This doesn't make sense as on my phone I have allowed read access (there's no sharing option per the documentation). As soon as I change out to let's say; let checkHkQuantityTypeAuthorization = HKObjectType.quantityType(forIdentifier: .stepCount) I am able to hit the case .sharingAuthorized case. What doesn't make sense is that even though it fails this check, if I just go ahead and query for the Activity Summary for the ring data via; let predicate = HKQuery.predicate(forActivitySummariesBetweenStart: startDateComponents, end: endDateComponents) let query = HKActivitySummaryQuery(predicate: predicate) { (query, summaries, error) { ... } It works just fine and I can pull the Activity data without changing any permissions in the Privacy settings of my iPhone or iPad. So, I know I can pull the data just fine, and that everything is set correctly for the Entitlements. I just want to make sure that the user has actually allowed me to before I try to pull the data. Additional Notes: The REALLY weird thing is that that when I try to pull the .stepCount, is that it will hit the .sharingDenied case if I only have the user do READ access. So, I've had to make my app also request for WRITE (share) access. Like this doesn't make any sense for me to request both READ and WRITE access to step count when my app only needs read access (like Activity Summary data). This seems like a bug in my opinion as I don't see anything related in the documentation in regards to this on the If this is how this is supposed to work given the discussion on the documentation; To help prevent possible leaks of sensitive health information, your app cannot determine whether or not a user has granted permission to read data. If you are not given permission, it simply appears as if there is no data of the requested type in the HealthKit store. If your app is given share permission but not read permission, you see only the data that your app has written to the store. Data from other sources remains hidden. Source: https://developer.apple.com/documentation/healthkit/hkhealthstore/1614154-authorizationstatus Then that is completely confusing. I want to check if I have permissions to read this data otherwise why bother trying to read the data or try to present anything to the user except that they need to allow access to me reading this data. Apple says that you should only request to relevant Health data when you need it. So this check is worthless if I am trying to check before I do the query because the UI wants to display data in regard to activity data. Honestly, this is really confusing if all this falls into the discussion item on the documentation and Apple needs to do better. EDIT: Further reading the very top of the method definition yields; Returns the app’s authorization status for sharing the specified data type. Like why Apple? I want to know if I can READ the type so I can tell the user to allow me access or not. This is frustrating.
0
1
483
Jul ’23