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

Posts under Health & Fitness subtopic

Post

Replies

Boosts

Views

Activity

HealthKit Error with retrieving step count data, error message: Unable to invalidate interval: no data source available
Our app has a feature that requires retrieving the user's step count data. However, since September of last year, some users have reported that they are unable to retrieve their step count. Some of these users are on iOS 15, while others are on iOS 16. Additionally, some users have Apple Watch, while others do not. Recently, we received an error log stating Unable to invalidate interval: no data source available. However, we are not trying to fetch a large interval of data at once, and the program has a maximum time interval.We are unable to find the problem. We'd appreciate it if someone could help identify the issue. Thank you.
0
1
832
Jun ’23
healthkit digital signature
I want to verify whether the healthkit data is tampered. Found this article https://developer.apple.com/documentation/healthkit/samples/adding_digital_signatures But it seems that nobody on the internet is talking about this. I want to know the workflow needed to use this feature. Should I store a list of trusted public keys? How can I get the signature and public from the metadata? Anyone with experience on this topic, please share!
0
0
449
Jun ’23
Problem inserting weather metadata into workout.
I have two related functions to retrieve the weather and then insert it into a "Live Workout Builder"... The first function calls the second to get the weather info after which it inserts the metadata into the builder. public func stopGatheringLocationData() { logger.info("Stopped gathering location data...") Task { let (humidity, temperature) = await getCurrentWeather() if humidity != nil && temperature != nil { logger.log("Current humidity \(humidity!), temperature: \(temperature!)") let metaData = [HKMetadataKeyWeatherHumidity: humidity!, HKMetadataKeyWeatherTemperature: temperature!] logger.log("Current metadata: \(metaData)") do { try await workoutManager.liveBuilder?.addMetadata(metaData) } catch { logger.error("FAILED to add weather metadata to workout -> \(error.localizedDescription)") } } else { logger.error("FAILED to retrieve weather data...") } } locationManager.stopUpdatingLocation() } private func getCurrentWeather() async -> (humidity: HKQuantity?, temperature: HKQuantity?) { // Get the weather for the starting location... let tempUnit = HKUnit.degreeFahrenheit() let humidityUnit = HKUnit.percent() guard let startingLocation else { logger.error("No starting location...") return (nil, nil) } do { let wx = try await wxService.weather(for: startingLocation) let humidity = wx.currentWeather.humidity let temp = wx.currentWeather.temperature.converted(to: .fahrenheit) let curWx = wx.currentWeather let wxAttr = try await wxService.attribution.legalAttributionText await MainActor.run { currentWx = curWx wxServiceAttribution = wxAttr } return (HKQuantity(unit: humidityUnit, doubleValue: humidity), HKQuantity(unit: tempUnit, doubleValue: temp.value)) } catch { logger.error("FAILED to retrieve weather data -> \(error.localizedDescription)") return (nil, nil) } } The two log statements in the first function print out the following information: [Location/Weather] Current humidity 52 %, temperature: 76.226 degF [Location/Weather] Current metadata: ["HKWeatherTemperature": 76.226 degF, "HKWeatherHumidity": 52 %] However, when I look at the workout in the Activity app on my iPhone, the map generated by my app is present but the weather information is missing. The data looks formatted correctly per the limited documentation but for some reason that data is just not showing up. Any help greatly appreciated...
1
0
695
Jun ’23
How long does Apple Watch keep HealthKit data?
I would like to create an Apple Watch only app that queries data such as blood oxygenation, heart varibility, number of steps, energy consumed, and other data of a similar nature recorded over the past month and performs calculations on them. I read from the HealthKit documentation that Apple Watch synchronizes data with iPhone and periodically deletes older data, and that I can get the date from which the data is available with earliestPermittedSampleDate(). Is there a risk that in general, by making queries to retrieve data up to a month old, the data will no longer be available? I need the app to work properly without needing an iPhone.
5
1
2.5k
3w
iOS AppleHealth - Push data with or without taking care of what is already stored
We have an app that tracks steps, distance, calories ... Now we want to push the data into Apple Health. The iPhone is tracking data by itself so I'm wondering if I should simply push the data we measured (which will be added to the existing data) or if I should calculate the difference from existing data to our measured data and just add what's missing. Example: Apple measured 500 steps from 11-12 am. Our bracelet measured 800 steps. While the phone might have been lying somewhere and the bracelet has always been worn, I rely on the bracelet data. So do I push 800 steps or 300 steps ? Many thanks, Sven
0
0
539
Jun ’23
Unable to see workout composition from preview in WorkoutKit
I am unable to see the workout composition from preview in the new WorkoutKit framework. This is reproducible on an iPhone running iOS 17.0 running xcode 15.0 beta 2. I downloaded the Sample Planner app that showcases the new WorkoutKit framework capabilities , introduced in the session 10016 of wwdc 23. I can create workout compositions but the preview presentation doesn’t work as expected. It shows a black screen without any info. I attached a screenshot. You can reproduce it on the sample app when showing the PresentPreviewDemo view.
4
1
1.3k
Sep ’23
Record workout on native WatchOS app in simulator
I'm trying to make a simple workout app that gets data from the health app (not an app that you use the record the actual workout). I can get data from the health app and manually add workouts but I couldn't find out how to record one with a map. Is there a way for me to either upload a GPX file for the workout, record it on the watch, or some other way to get the workout with a map on the simulator.
0
0
698
Jul ’23
Get workouts with map on apple watch simulator
Hi! I am trying to build a fitness app and running it on an iPhone simulator. So far, the app is working and can detect workouts and display them. Now, I want to make the app work for workouts that have a map but I couldn't find how to add a map or any other kind of data without recording it on the apple watch which I can't do because there is no workout app displayed on the simulated watch. Thanks.
0
0
616
Jul ’23
Difference in HealthKit step count results?
I have a question regarding the number of steps that can be retrieved from HealthKit. Is there any difference in the result of the number of steps when the number of steps is acquired immediately after walking and when it is acquired 10 minutes later? For example, the following image. First, the data is acquired from HealthKit and 0 steps are returned. Within 1 minute, the user takes 50 steps. Immediately after taking 50 steps, data is retrieved from HealthKit and 0 steps are returned. After 10 minutes, HealthKit retrieves data and returns 50 steps without taking a single step. Sometimes the correct number of steps is obtained immediately after walking, and sometimes the correct number of steps is not obtained until some time has elapsed.
0
0
528
Jul ’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
3
966
Jul ’23
Fetching mindfull minutes from iCloud
I want to create an app-less app that uses healthkit information that would be retrieved from the iCloud rather than from the device itself (Getting healthkit data from an app is well described). Is there any possible way to connect to my iCloud with a webhook directly?
Replies
0
Boosts
0
Views
371
Activity
May ’23
Custom HealthKit samples
Is it possible to create a custom HealthKit sample type? Let's say for example I want to tack how many alcoholic beverages are consumed? Or how many times a user smokes each day? There is not a category in HealthKit for these today is it possible for my app to add them as custom data types?
Replies
0
Boosts
0
Views
970
Activity
Jun ’23
HealthKit Error with retrieving step count data, error message: Unable to invalidate interval: no data source available
Our app has a feature that requires retrieving the user's step count data. However, since September of last year, some users have reported that they are unable to retrieve their step count. Some of these users are on iOS 15, while others are on iOS 16. Additionally, some users have Apple Watch, while others do not. Recently, we received an error log stating Unable to invalidate interval: no data source available. However, we are not trying to fetch a large interval of data at once, and the program has a maximum time interval.We are unable to find the problem. We'd appreciate it if someone could help identify the issue. Thank you.
Replies
0
Boosts
1
Views
832
Activity
Jun ’23
healthkit digital signature
I want to verify whether the healthkit data is tampered. Found this article https://developer.apple.com/documentation/healthkit/samples/adding_digital_signatures But it seems that nobody on the internet is talking about this. I want to know the workflow needed to use this feature. Should I store a list of trusted public keys? How can I get the signature and public from the metadata? Anyone with experience on this topic, please share!
Replies
0
Boosts
0
Views
449
Activity
Jun ’23
IOS 17 mental health register in healthKit
How can I access the mental health record in healthKit to use it in my app? I am developing an application that records how the user feels in some circumstances. At WWDC23, a new iOS application was presented that records this type of data in the health application. I would like to know if it is available to use it in my applications
Replies
0
Boosts
1
Views
778
Activity
Jun ’23
Problem inserting weather metadata into workout.
I have two related functions to retrieve the weather and then insert it into a "Live Workout Builder"... The first function calls the second to get the weather info after which it inserts the metadata into the builder. public func stopGatheringLocationData() { logger.info("Stopped gathering location data...") Task { let (humidity, temperature) = await getCurrentWeather() if humidity != nil && temperature != nil { logger.log("Current humidity \(humidity!), temperature: \(temperature!)") let metaData = [HKMetadataKeyWeatherHumidity: humidity!, HKMetadataKeyWeatherTemperature: temperature!] logger.log("Current metadata: \(metaData)") do { try await workoutManager.liveBuilder?.addMetadata(metaData) } catch { logger.error("FAILED to add weather metadata to workout -> \(error.localizedDescription)") } } else { logger.error("FAILED to retrieve weather data...") } } locationManager.stopUpdatingLocation() } private func getCurrentWeather() async -> (humidity: HKQuantity?, temperature: HKQuantity?) { // Get the weather for the starting location... let tempUnit = HKUnit.degreeFahrenheit() let humidityUnit = HKUnit.percent() guard let startingLocation else { logger.error("No starting location...") return (nil, nil) } do { let wx = try await wxService.weather(for: startingLocation) let humidity = wx.currentWeather.humidity let temp = wx.currentWeather.temperature.converted(to: .fahrenheit) let curWx = wx.currentWeather let wxAttr = try await wxService.attribution.legalAttributionText await MainActor.run { currentWx = curWx wxServiceAttribution = wxAttr } return (HKQuantity(unit: humidityUnit, doubleValue: humidity), HKQuantity(unit: tempUnit, doubleValue: temp.value)) } catch { logger.error("FAILED to retrieve weather data -> \(error.localizedDescription)") return (nil, nil) } } The two log statements in the first function print out the following information: [Location/Weather] Current humidity 52 %, temperature: 76.226 degF [Location/Weather] Current metadata: ["HKWeatherTemperature": 76.226 degF, "HKWeatherHumidity": 52 %] However, when I look at the workout in the Activity app on my iPhone, the map generated by my app is present but the weather information is missing. The data looks formatted correctly per the limited documentation but for some reason that data is just not showing up. Any help greatly appreciated...
Replies
1
Boosts
0
Views
695
Activity
Jun ’23
Medications in HealthKit
Is Medication tracking features to HealthKit have read/write access to developers from ios 17.
Replies
0
Boosts
4
Views
516
Activity
Jun ’23
How long does Apple Watch keep HealthKit data?
I would like to create an Apple Watch only app that queries data such as blood oxygenation, heart varibility, number of steps, energy consumed, and other data of a similar nature recorded over the past month and performs calculations on them. I read from the HealthKit documentation that Apple Watch synchronizes data with iPhone and periodically deletes older data, and that I can get the date from which the data is available with earliestPermittedSampleDate(). Is there a risk that in general, by making queries to retrieve data up to a month old, the data will no longer be available? I need the app to work properly without needing an iPhone.
Replies
5
Boosts
1
Views
2.5k
Activity
3w
iOS AppleHealth - Push data with or without taking care of what is already stored
We have an app that tracks steps, distance, calories ... Now we want to push the data into Apple Health. The iPhone is tracking data by itself so I'm wondering if I should simply push the data we measured (which will be added to the existing data) or if I should calculate the difference from existing data to our measured data and just add what's missing. Example: Apple measured 500 steps from 11-12 am. Our bracelet measured 800 steps. While the phone might have been lying somewhere and the bracelet has always been worn, I rely on the bracelet data. So do I push 800 steps or 300 steps ? Many thanks, Sven
Replies
0
Boosts
0
Views
539
Activity
Jun ’23
visionOS and Healthcare
I would love to chat with someone around the possibilities surrounding healthcare and visionOS. I would LOVE to work with incorporating VisionOS into my SIMLab, especially for my surgery residents and eventually with my virtual providers.
Replies
1
Boosts
0
Views
861
Activity
Jul ’23
real time body temperature data from HealthKit
I am building an app that requires real time (minute level) body temperature data. I couldn't find the api to do that. Does HealthKit offer this data?
Replies
0
Boosts
1
Views
829
Activity
Jun ’23
Unable to see workout composition from preview in WorkoutKit
I am unable to see the workout composition from preview in the new WorkoutKit framework. This is reproducible on an iPhone running iOS 17.0 running xcode 15.0 beta 2. I downloaded the Sample Planner app that showcases the new WorkoutKit framework capabilities , introduced in the session 10016 of wwdc 23. I can create workout compositions but the preview presentation doesn’t work as expected. It shows a black screen without any info. I attached a screenshot. You can reproduce it on the sample app when showing the PresentPreviewDemo view.
Replies
4
Boosts
1
Views
1.3k
Activity
Sep ’23
Record workout on native WatchOS app in simulator
I'm trying to make a simple workout app that gets data from the health app (not an app that you use the record the actual workout). I can get data from the health app and manually add workouts but I couldn't find out how to record one with a map. Is there a way for me to either upload a GPX file for the workout, record it on the watch, or some other way to get the workout with a map on the simulator.
Replies
0
Boosts
0
Views
698
Activity
Jul ’23
Get workouts with map on apple watch simulator
Hi! I am trying to build a fitness app and running it on an iPhone simulator. So far, the app is working and can detect workouts and display them. Now, I want to make the app work for workouts that have a map but I couldn't find how to add a map or any other kind of data without recording it on the apple watch which I can't do because there is no workout app displayed on the simulated watch. Thanks.
Replies
0
Boosts
0
Views
616
Activity
Jul ’23
healthDataAccessRequest
Has anyone used healthDataAccessRequest successfully in SwiftUI? How does parameter trigger work?
Replies
0
Boosts
1
Views
758
Activity
Jul ’23
Difference in HealthKit step count results?
I have a question regarding the number of steps that can be retrieved from HealthKit. Is there any difference in the result of the number of steps when the number of steps is acquired immediately after walking and when it is acquired 10 minutes later? For example, the following image. First, the data is acquired from HealthKit and 0 steps are returned. Within 1 minute, the user takes 50 steps. Immediately after taking 50 steps, data is retrieved from HealthKit and 0 steps are returned. After 10 minutes, HealthKit retrieves data and returns 50 steps without taking a single step. Sometimes the correct number of steps is obtained immediately after walking, and sometimes the correct number of steps is not obtained until some time has elapsed.
Replies
0
Boosts
0
Views
528
Activity
Jul ’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.
Replies
0
Boosts
3
Views
966
Activity
Jul ’23
Initialize HKDeletedObject for unit test
I would like to initialize a HKDeletedObject for an unit test. Before diving into NSCoder: Has somebody done this before and can give some advice? Thanks in advance!
Replies
1
Boosts
0
Views
635
Activity
Jul ’23
Does the HealthKit allow access to real time sleep stage data for Apple Watch?
Is it possible to build a watch app that has real time access to sleep stages and could determine whether a user is asleep?
Replies
0
Boosts
0
Views
701
Activity
Jul ’23
WorkoutKit: Alert - HeartRateZoneAlert vs PowerZoneAlert
Hello, I'm trying to understand what's the difference between: HeartRateZoneAlert: static func heartRate(zone: Int) -> Self PowerZoneAlert : static func power(zone: Int) -> Self And also, why HeartRate alerts support range, but Power doesn't support Range?
Replies
1
Boosts
0
Views
881
Activity
Sep ’23