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

Issue with Air play since new update iOs18 (apple fitness App)
Can’t start fitness video with my iPhone on my tv since new update 18.1. Air play is connecting I see the countdown then the dots rolling but nothing happens and I end up receiving a « can’t read video » message. I’m using an iphone 16 pro max, an apple watch ultra (1st gen) and an apple tv HD (A1625 model). I have almost the same issue with a more recent Apple TV, but on that one it’s just painfully long before the video starts but it does start eventually (just taking much longer than it used to). That some tv is an A2843 model (apple tv 4k 3rd gen). Has anyone else had this issue?
1
0
304
Oct ’24
Missing manual - Training Load, .estimatedWorkoutEffortScore, .workoutEffortScore - Where are the Apple RPE CR-10 scale docs?
Apple is using the RPE scale for workout effort scores. This stands for the Rate of Perceived Exertion. They're specifically using the CR-10 scale, at least from what I can tell by saving values to HealthKit. They only accept value between 0 and 10. Has anyone been able to find a scientific or academic paper on how they have chosen their different effort breakouts? Right from the Fitness app on iPhone and Activity app on Apple Watch: 1-3 Easy 4-6 Moderate 7-8 Hard 9-10 All Out There is zero documentation on these new types, which makes it difficult for workout recording apps to properly and appropriately save this new data type. Sure, we can use the Apple apps as a reference, but since there isn't a built-in Apple SwiftUI sheet to present this data, and no references to academia to point our users to, our solutions would just look the same. FB15315876 - Documentation / HealthKit: Publish documentation about .workoutEffortScore and .estimatedWorkoutEffortScore FB15316109 - Documentation / HealthKit: Add documentation to .estimatedWorkoutEffortScore and .workoutEffortScore that you can't save those samples via the save API and that they must be related and let that API save the sample FB15316251 - Documentation / HealthKit: Add documentation for acceptible values of .estimatedWorkoutEffortScore and .workoutEffortScore - don't rely on a runtime error! Apple missed making an enum for all third party developers this year.
0
1
256
Oct ’24
How to add "Estimated Time in Each Heart Rate Zone" info to my custom HKWorkout when viewed in Apple Fitness app?
Hello, I’m currently developing a fitness app for watchOS that lets a user to manually set a desired heart rate target zone (enter numbers representing the lower and upper boundaries) and start a workout (right now it’s only “Other” type). After that my app monitors user’s heart rate and alerts them when they’re out of zone. When user ends the workout, the info about this workout appears on “Fitness” iOS app, and user can see the workout data like Workout Time, Active and Total Calories, Avg. Heart Rate. Also user can see Heart Rate chart with info how their heart rate was changing during a workout (see the Figure 1). Now to the question. When user clicks “Show More” button above the Heart Rate chart, they can see the same Heart Rate chart and another one, with Post-Workout Heart Rate (see the Figure 2). But there is no “Estimated time in each heart rate zone” as one can see in the workout’s details that were recorded from Apple’s workout (watchOS “Workout” app, for a workout of “Other” type as well). Please see the Figure 3. The question is: is it possible to add “Estimated time in each heart rate zone” to workout recorded via my third-party app so it would look like on the Figure 3 in "Fitness" iOS app, and if it's possible, what steps should I undertake to implement this ? Thanks in advance! I posted the screenshots in the replies to the post, because otherwise I was not able to submit a post ("sensitive language" warning, I suspect it's because of the ids in the attached screenshot's urls)
2
0
704
May ’24
internal healthkit error: "Unable to invalidate interval: no data source avallable"
we are seeing what appears to be an internal healthkit error appearing in our app.  not sure if it's connected, but we've mostly seen it reported on devices running ios 16.  even though our app's primary language is japanese, and in all reported occurrences the app was running in japanese, the error message itself appears in english.  searching the error string on the web yields surprisingly few results (including only two mentions on this forum that i could find, neither of which seemed relevant).  this would seem to suggest that it's coming from something deep inside healthkit, since the error message is not localized.  in all reported cases, the user had recently upgraded to a new iphone.  in most cases, the problem only occurs on the new device even though everything had been working correctly prior to the upgrade.  the error occurs when the app is unable to read step count data from healthkit. we have confirmed that the app has been granted access permissions to all health data via os settings.  we've also tried having the user toggling those settings off, then back on, rebooting the device, deleting and reinstalling the app, etc., to no avail. the error message is "Unable to invalidate interval: no data source avallable." we'd appreciate it if anyone can shed more light on this issue. thanks!
4
3
1.3k
Nov ’22
Adding workoutEffortScore to HKWorkout
I'm trying to hook into the new workoutEffort score supported in iOS 18, I am collecting this information from users when they submit their workout and trying to add a sample to the HKWorkout in the same manner as I've been adding other samples like bodyweight, calories burned, etc. I'm receiving the error: HKWorkout: Sample of type HKQuantityTypeIdentifierWorkoutEffortScore must be related to a workout I tried adding the samples using HKWorkoutBuilder.add([samples]) as which has been working perfectly for calories burned & bodyweight, but I am receiving the above error for workoutEffortScore As a second approach, I tried adding the sample after I called finishWorkout on the HKWorkoutBuilder and received back the HKWorkout object using HKHealthStore.add([samples], to: HKWorkout) and am still receiving the same error! I don't know otherwise how to relate a sample to a workout, I thought those were the APIs to do so? I'm using Xcode 16.0 RC (16A242) and testing on an iOS 16 Pro simulator
4
1
686
Sep ’24
HealthKit permission sheet appears every time for some users - bug?
The HealthKit permission sheet is showing up every time the app opens for a few users of my app. It doesn't matter what action they take in the sheet. I have had them try toggling the permissions from the HealthKit system settings but that did not happen to fix the problem. Has anyone experienced this problem or know a fix? Its affecting a few users of my app. I haven't been able to find what in my code could be doing this, I suspect its a bug on HealthKit's side for specific users. I can't find anyone reporting this problem elsewhere so I have to assume its my fault, but the docs clearly state that the permission sheet will only be presented once.
7
9
1.2k
Feb ’24
How the iOS 18 Control Widget displays an AppIntentError to the user.
My app is an outdoor exercise tracking app that allows you to start exercising from the Control widget。 I want to prompt the user with an AppIntentError.PermissionRequired.location error when the user doesn't authorize Core Location permissions. When I throw error in the Intent, tap the Control widget doesn't do anything and doesn't give the user any indication of what's happening
2
0
266
Sep ’24
HealthKit bugs related to new workout effort score - heart rate samples take forever to fetch, Health app displays invalid data
I am encountering issues on my device running iOS 18 that fetching heart rate samples associated to a given workout is very slow. Like 10+ seconds slow. This is unacceptable and unexpected. In producing a video to attach to a feedback, I also observed that Apple Health app displays incorrect information if a workout effort score is associated to a workout. In this image, you can see the Health app bug: Total Resting Energy != Estimated Workout Effort Score Here is the same workout after I delete the workout effort score using the Apple Health app: Can anyone else see if attempting to view 'heart rate' data within the workout summary in Apple Health is unbearably slow if that workout also has an effort score associated? My steps: Record workout (Apple Activity app on watchOS) Associate effort score View the workout on Apple Health (iOS) Attempt to view it's heart rate samples Observe very slow loading times Observe the incorrect cell label and value and disappearance of resting energy cell data Remove/disassociate the effort score from the workout by tapping the workout effort row, and swipe to delete the value. Navigate back, navigate back, and then go into the workout detail again At this time the UI fixes itself, but the loading of heart rate data is still super slow FB15269657 - HealthKit: Sample query to fetch heart rate samples associated to a workout is taking over 10 seconds - computing 'time in heart rate zone' FB15278790 - Health: Workout summary 'Total Resting Energy' label has value of 'Estimated Workout Effort Score' for a value, pushed view shows empty
0
0
320
Sep ’24
Wake-up detection with HealthKit
Hello HealthKit Experts & Enthusiasts! I am building an app called one sec which forces people to take a deep breath before they can use social media apps (it’s using Shortcuts Automations for that). One important feature of one sec is the Good Morning Countdown: For a specified time after waking up (e.g. 30mins) selected apps are blocked completely. This helps to start the day screen-free. They way it works is, the user grants access to read HKCategoryTypeIdentifier.sleepAnalysis data. I have implemented a HKObserverQuery and enableBackgroundDelivery in order to be informed whenever new HKCategoryTypeIdentifier.sleepAnalysis becomes available. I noticed that when I have my device connected to Xcode, this works as expected. However, when I quit the app and launch it from my Home Screen, my observer query is not informed about new sleep data (except when my app is running in foreground). Any ideas? Furthermore, I have noticed that sometimes sleep data is provided delayed to HealthKit, many minutes (sometimes even longer) after waking up, no sleep samples are to be found in the Health app. Of course, for my app it is crucial to get accurate + timely so apps can be blocked accordingly. Is this an issue that the Apple Watch first needs to send the samples to the phone? Thanks a lot for your help!
1
1
382
Sep ’24
HealthKit ID is the same with another Device
HealthKit tracker Id is the same with another Device, We are using an application to track our health progress and we are trying to connect our HealthKit to monitor our health data (steps and calories) but unfortunately we can't connect to the app (another application) at the same time because two devices is sharing just one health kit tracker ID. Can anyone help me to resolve this issue? Old phone was used by the other person before changing to new phone
1
0
261
Aug ’24
Overlapping Segments and Duplicate Start Times in Workout Data
Hello, We're encountering overlapping segments and discrepancies when analyzing running/workout data for a 5-mile run. The expected splits for the run are: 8:39 9:06 8:30 8:39 8:43 0:08 However, the raw data includes segments where start times begin before the previous segment ends, and there are duplicate start times. Below is a sample of the raw data: "startDate": "2024-09-09T19:32:00.308-0400", "eventType": "segment", "eventTypeInt": 7, "endDate": "2024-09-09T19:37:56.135-0400" }, { "startDate": "2024-09-09T19:32:00.308-0400", "eventType": "segment", "eventTypeInt": 7, "endDate": "2024-09-09T19:41:08.476-0400" },``` // Here's an example of where the second segment start time falls in side the first segments startDate and endDate "startDate": "2024-09-09T19:54:22.658-0400", "eventType": "segment", "eventTypeInt": 7, "endDate": "2024-09-09T19:59:41.215-0400" }, { "startDate": "2024-09-09T19:58:44.624-0400", "eventType": "segment", "eventTypeInt": 7, "endDate": "2024-09-09T20:07:23.216-0400"
8
0
525
Sep ’24
How to start a legit companion App from iPhone App which uses CoreMotion?
I have an iOS application for the iPhone that works with a companion app on the Apple Watch, using CoreMotion to provide data. How can I launch the Apple Watch companion app from the iPhone app before starting data recording? Can startWatchAppWithWorkoutConfiguration(...) be used for this without registering an actual workout with HealthKit? Or can I register this action as a new custom workout?
1
0
169
Sep ’24
HKLiveWorkoutBuilder only reporting heart rate - No other measurements
I'm using Healthkit with the following H/W specs: Apple Watch, series 8, OS: 10.6.1 (21U580) iPhone 11 Pro, OS: 17.6.1 Mac Studio M1 Xcode ver: 16.0 (16A242d) I am trying to get Apple Watch to report heart rate, HRV, respiratory rate, and body temperature using Healthkit's HKLiveWorkoutBuilder implementing HKLiveWorkoutBuilderDelegate's workoutBuilder method. However, the only reported value that is found from the workoutBuilder method's collectedTypes (a Set of HKSampleType objects) is HKQuantityTypeIdentifierHeartRate. Nothing for HRV, respiratory rate, or body temperature. All entitlements are set up, the plist filled in, and capabilities in place. Not sure why only the heart rate is reported from the watch but nothing else. I've scoured StackOverflow, Apple developer forums, even ChatGPT but none of the solutions work. Any help most appreciate! The model code is: import Foundation import HealthKit class WatchModel: NSObject, HKLiveWorkoutBuilderDelegate, HKWorkoutSessionDelegate { private let healthStore = HKHealthStore() private var workoutSession: HKWorkoutSession! private var workoutBuilder: HKLiveWorkoutBuilder! override init() { super.init() requestAuthorization() startWorkoutSession() } private func requestAuthorization() { let heartRateType = HKQuantityType.quantityType(forIdentifier: .heartRate)! let respiratoryRateType = HKQuantityType.quantityType(forIdentifier: .respiratoryRate)! let HRVRateType = HKQuantityType.quantityType(forIdentifier: .heartRateVariabilitySDNN)! let temperatureRateType = HKQuantityType.quantityType(forIdentifier: .bodyTemperature)! let healthDataTypes: Set = [heartRateType, respiratoryRateType, HRVRateType, temperatureRateType] healthStore.requestAuthorization(toShare: healthDataTypes, read: healthDataTypes) { (success, error) in if !success { print("Authorization failed") } } } func workoutSession(_ workoutSession: HKWorkoutSession, didChangeTo toState: HKWorkoutSessionState, from fromState: HKWorkoutSessionState, date: Date) { } func workoutSession(_ workoutSession: HKWorkoutSession, didFailWithError error: any Error) { } func workoutBuilderDidCollectEvent(_ workoutBuilder: HKLiveWorkoutBuilder) { } func startWorkoutSession() { let configuration = HKWorkoutConfiguration() configuration.activityType = .other configuration.locationType = .indoor do { workoutSession = try HKWorkoutSession(healthStore: healthStore, configuration: configuration) workoutBuilder = workoutSession.associatedWorkoutBuilder() workoutBuilder.delegate = self workoutBuilder.dataSource = HKLiveWorkoutDataSource(healthStore: healthStore, workoutConfiguration: configuration) let dataSource = HKLiveWorkoutDataSource(healthStore: healthStore, workoutConfiguration: configuration) let respiratoryRate = HKQuantityType(.respiratoryRate) dataSource.enableCollection(for: respiratoryRate, predicate: nil) let bodyTemp = HKQuantityType(.bodyTemperature) dataSource.enableCollection(for: bodyTemp, predicate: nil) let hrv = HKQuantityType(.heartRateVariabilitySDNN) dataSource.enableCollection(for: hrv, predicate: nil) workoutSession.delegate = self workoutSession.startActivity(with: Date()) workoutBuilder.beginCollection(withStart: Date(), completion: { (success, error) in if let error = error { print("Error starting collection: \(error.localizedDescription)") } }) } catch { print("Failed to start workout session: \(error.localizedDescription)") } } func workoutBuilder(_ workoutBuilder: HKLiveWorkoutBuilder, didCollectDataOf collectedTypes: Set<HKSampleType>) { print("collected types: \(collectedTypes)") for type in collectedTypes { if let quantityType = type as? HKQuantityType { if quantityType == HKQuantityType.quantityType(forIdentifier: .heartRate) { if let heartRateQuantity = workoutBuilder.statistics(for: quantityType)?.mostRecentQuantity() { let heartRateUnit = HKUnit(from: "count/min") let heartRateValue = heartRateQuantity.doubleValue(for: heartRateUnit) print("heart rate: \(heartRateValue)") } } if quantityType == HKQuantityType.quantityType(forIdentifier: .heartRateVariabilitySDNN) { if let hrvQuantity = workoutBuilder.statistics(for: quantityType)?.mostRecentQuantity() { let hrvUnit = HKUnit.secondUnit(with: .milli) let hrvValue = hrvQuantity.doubleValue(for: hrvUnit) print("HRV: \(hrvValue)") } } if quantityType == HKQuantityType.quantityType(forIdentifier: .bodyTemperature) { if let bodyTempQuantity = workoutBuilder.statistics(for: quantityType)?.mostRecentQuantity() { let tempUnit = HKUnit.degreeCelsius() let tempValue = bodyTempQuantity.doubleValue(for: tempUnit) print("body temp: \(tempValue)") } } if quantityType == HKQuantityType.quantityType(forIdentifier: .respiratoryRate) { if let respRateQuantity = workoutBuilder.statistics(for: quantityType)?.mostRecentQuantity() { let respRateUnit = HKUnit(from: "count/min") let respRateValue = respRateQuantity.doubleValue(for: respRateUnit) print("breathing: \(respRateValue)") } } } } } }
6
0
528
Sep ’24
recoverActiveWorkoutSession() inaccurate for paused sessions
When a workout session is being recovered, if it is paused, the elapsed time will be incorrect. It will seem like that workout never was paused. The recovery works fine if the workout was never paused. Steps to reproduce: Implement recoverActiveWorkoutSession Start workout Pause session and print the elapsed time Stop simulator / cause crash When recoverActiveWorkoutSession is called the elapsed time will not equal the elapsed time when the session was paused. Here is my implementation. I haven't seen any examples online. guard let recovered = try? await healthStore.recoverActiveWorkoutSession() else {return} self.session = recovered self.builder = recovered.associatedWorkoutBuilder() self.session?.delegate = self self.builder?.delegate = self self.builder?.dataSource = HKLiveWorkoutDataSource(healthStore: healthStore, workoutConfiguration: recovered.workoutConfiguration) self.sessionState = recovered.state
1
0
302
Sep ’24
Regular step count fetch and upload to API
Hello all, I am quite new to iOS and Swift, and before venturing further, I feel it's better to ask for advice. I have build a Type I diabetes simulator running as a NodeJS application on a server. The clients authenticate via a browser using Fitbit/Google oauth2, set up a virtual patient, then take care of the patient 24/7. The app imports the users steps and heartrate, as these influence the blood sugar variations. (https://cgmsim.com) I designed a companion app with Expo, adding high/log blood glucose alerts with push notifications. If the user doesn't have a Fitbit tracker or doesn't use Google Fit, I'd like to send their HealthKit step counts to the backend. (Using sensor data directly in Android). It works using Expo's Background Fetch and TaskManager, but the uploads from the iOS device are very irregular. I set up silent push notifications from the backend to wake up the app in the background and trigger the step count upload. It works, but it is not reliable enough. I now wrote my first local native module for iOS, where a HKObserverQuery listening for new step events, making the upload and sending the count to the JS for rendering. I used enableBackgroundDelivery and BackgroundTask for uploading the results. All the entitlements and Info.plist entries should be ok. Still my app works well only in the foreground, and not upload at all happens when in the background. As we all do, I asked Claude, and it assured me th app should work. I have doubts though, as I noticed how strict iOS is about executing background tasks. So... should I even expect this to work ?
1
0
431
Sep ’24
WatchOS Fall Detection Consequences
My team and I are working on an app for a private emergency helpline. Now as far as I understand the (sparse) API documentation for fall detection, given the appropriate entitlement, the following happens upon a detected fall: The Standard UI will be opened with the options to a) call SOS b) acknowledge the fall but state that you're fine though, c) deny the fall, and (implicitly after 60 seconds on inactivity) call SOS because you didn't react. All fall detection apps will then receive a bit of background time and get the func fallDetectionManager(CMFallDetectionManager, didDetect: CMFallDetectionEvent, completionHandler: () -> Void) called with the appropriate event value. Now that's all good and it sounds like the custom fall detection is additive to the standard system. But but why is there something like that in the entitlement request form sheet: For any emergency calling features that you do not provide, explain any mitigations you use to make sure the user receives emergency services support that’s as close as possible to what they’d receive had they placed an emergency call natively. This sounds like our app would rather be a drop-in to the standard SOS service ­– in contrast to being additive and also in contrast to what the API documentation infers. Am I misunderstanding something?
0
0
272
Sep ’24
Workouts, activity rings, samples and more not syncing across devices running iOS 18 RC and watchOS 11 RC
I noticed last night that workouts I have been recording on my main carry device running 17.6.x have not been syncing to my beta devices running iOS 18 RC, iPadOS 18 RC and watchOS 11 RC. All devices are using the same Apple Account and I have iCloud enabled for Health data. The iPad running the RC has the syncing enabled in Profile. Is anyone else experiencing health data not propagating to the 18.x devices? Some of data exists on all devices but not all. For good measure I left the device unlocked on the health app last night for a long period of time to let it do its thing. This morning the data still hadn't propagated. I disabled and reenabled the synchronization on my iPad having chosen to delete all samples when disabling it. Hopefully all of my data dating back to the first Apple Watch in 2014 restores. FWIW my data set according to iCloud settings my health dataset is just shy of 650 MB. FB15102443 - Health / HealthKit: Workouts, activity rings, sample data, and more not syncing via iCloud to 18 RC device
0
0
314
Sep ’24
Health Export not complete
Good evening, when I use the automatic export feature from my iPhone, it successfully exports data. When reading the Export.xml file it is dispayed completely, with about 3 mio lines. When I check the file I see, that a lot of data is missing. E.g. the iPhone dispays the heart rates for several exercises (from last year), which don't have any correspondence in the export.xml file. Current exercises have. I am a developer myself and parsed all files without any error. My iPhone has enough free space (200GB or so) and iCloud has more than a TB free. Internet is connected via 1GBit line, WLAN with 800MBit and everything runs smooth. I would like to get a COMPLETE export of all the health data, without having to write a program on my own to accomplish this. Thank you. /C
0
0
231
Aug ’24