Use HealthKit to enable your iOS and watchOS apps to work with the Apple Health app.

All subtopics
Posts under Health and Fitness topic

Post

Replies

Boosts

Views

Activity

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
658
Sep ’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
545
Aug ’23
Creating a ECG sample programmatically via Apple Watch
I noticed that there was the ECG app on the Apple Watch that enabled you to gather an ECG sample. Was there any method that could programmatically enable tracking within your own watchOS application? Currently, the only way I can physically get samples is if I leave the application I'm building to physically start an ECG session through the ECG app which is not ideal.
1
0
710
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
583
Aug ’23
Inquiry on Enabling Health-Related Features of Apple Watch Series 8 in Pakistan
Dear Apple Support Team, I am reaching out to inquire about the process to enable the health-related features of the Apple Watch Series 8 in Pakistan. Your valuable guidance and assistance in making these features accessible would be greatly appreciated. Thank you for your attention to this matter. Sincerely,
0
0
655
Aug ’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
700
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
CareKit: Unable to adopt protocol 'OCKSurveyTaskViewControllerDelegate'
Hello all, this could surely be a newbie mistake but I'm unable to adopt this protocol to my class object I've created in a new project. The Error: "Cannot find type 'OCKSurveyTaskViewControllerDelegate' in scope" import CareKit import CareKitUI import CareKitStore import ResearchKit import UIKit import os.log final class CareFeedViewController: OCKDailyPageViewController, OCKTaskSurveyViewControllerDelegate { } However, I've been able to locate the 'OCKSurveyViewController.swift" file in the CareKit framework from SPM which has the protocol defined there, but I'm still unable to utilize it. Was the protocol only for demonstration purposes and not for use outside of the WWDC21 - CareKit Code Along?
1
0
1.4k
Jul ’23
watchOS 9 WidgetKit complications missing com.apple.developer.healthkit entitlement
I have an iOS/wOS app that launched last year. Now I want to add complications to it and use the new way of doing complications with WidgetKit. I have everything in place up to the point where I'm supposed to read the data from Health to display it, where it fails with Missing com.apple.developer.healthkit entitlement. This is the new extension I've added It's embedded in the WatchKit app NOT in the WatchKit Extension and I've added permission to read health data directly in the info.plist for the extension I pull the data from the TimelineProvider protocol method func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> ()) { let currentDate = Date() var entries: [WorkoutEntry] = [] ComplicationHealthManager.loadPreviousWorkouts { workout in let workoutEntry = WorkoutEntry(date: currentDate, workout: workout) entries.append(workoutEntry) let timeline = Timeline(entries: entries, policy: .after(currentDate)) completion(timeline) } } with the help of a small manager class class ComplicationHealthManager: ObservableObject { static func loadPreviousWorkouts(completion: @escaping (HKWorkout?) -> Void) { let healthStore: HKHealthStore = HKHealthStore() let workoutPredicate = HKQuery.predicateForWorkouts(with: .traditionalStrengthTraining) let compound = NSCompoundPredicate(andPredicateWithSubpredicates: [workoutPredicate]) let sortDescriptor = NSSortDescriptor(key: HKSampleSortIdentifierEndDate, ascending: false) let query = HKSampleQuery( sampleType: .workoutType(), predicate: compound, limit: 0, sortDescriptors: [sortDescriptor]) { (query, samples, error) in guard let samples = samples as? [HKWorkout], error == nil else { completion(nil) return } let calendar = Calendar.current let todaysSamples = samples.filter{ calendar.isDateInToday($0.endDate) }.last completion(todaysSamples) } healthStore.execute(query) } } The issue is in the closure for the health query where it returns with no workouts but an error stating Error Domain=com.apple.healthkit Code=4 "Missing com.apple.developer.healthkit entitlement." UserInfo={NSLocalizedDescription=Missing com.apple.developer.healthkit entitlement.} The problem here is I don't understand where and how to add an entitlement for the complication extension or the WatchKit app, as none of them have the option for health. I have a health entitlements set for the iPhone app and the WatchKit Extension.
2
0
1.3k
Jun ’23
RAW IMU Data stops logging on wrist down
Hello, I'm having a problem on my watchOS app where even though I have instantiated a WKExtendedRuntimeSession the app stops logging IMU data a few seconds after the watch has gone to sleep. This happens on my Apple Watch Series 6, but does not happen on the latest Apple Watch Series 8. CPU usage in both cases does not exceed 70%, so I doubt my app is exceeding the limits thus cancelling the WKExtendedRuntimeSession. To back that up, I am not getting the WKExtendedRuntimeSessionInvalidationReason trigger I was suggested to put in place form the documentation. I have tested a couple of different sample rates, this does not seem to happen with a sample rate as low as 1, but does happen already with a sample rate of 30. Could it be a watch limitation, or am I forgetting something? P.S. I have also set the background mode to physical therapy and ticket the workout processing box.
0
0
1k
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
700
Jun ’23
Can't run Research and Care App (WWDC Code Along)
Hello everyone, I just started watching the WWDC21 Code Along "Build a Research and Care App, Part 1" and wanted to run the project in Xcode. However, when I clone the Repo with the recommended git clone --recurse-submodule https://github.com/carekit-apple/WWDC21-RecoverApp.git command and open the project, I get the following error: /WWDC21-RecoverApp/Recover Part 1/Recover.xcodeproj This Copy Files build phase contains a reference to a missing file 'ResearchKit.framework'. /WWDC21-RecoverApp/ResearchKit only contains 2 files (CONTRIBUTING.md and LFS-Files). I was wondering how I could get the project up and running and if there are additional steps to take, that I didn't see in the presentation / Github Readme. Thanks!
3
0
2.2k
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.
0
1
832
Jun ’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!
Replies
0
Boosts
0
Views
658
Activity
Sep ’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?
Replies
1
Boosts
0
Views
545
Activity
Aug ’23
Creating a ECG sample programmatically via Apple Watch
I noticed that there was the ECG app on the Apple Watch that enabled you to gather an ECG sample. Was there any method that could programmatically enable tracking within your own watchOS application? Currently, the only way I can physically get samples is if I leave the application I'm building to physically start an ECG session through the ECG app which is not ideal.
Replies
1
Boosts
0
Views
710
Activity
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 :)
Replies
0
Boosts
0
Views
583
Activity
Aug ’23
Inquiry on Enabling Health-Related Features of Apple Watch Series 8 in Pakistan
Dear Apple Support Team, I am reaching out to inquire about the process to enable the health-related features of the Apple Watch Series 8 in Pakistan. Your valuable guidance and assistance in making these features accessible would be greatly appreciated. Thank you for your attention to this matter. Sincerely,
Replies
0
Boosts
0
Views
655
Activity
Aug ’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
702
Activity
Jul ’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
700
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
CareKit: Unable to adopt protocol 'OCKSurveyTaskViewControllerDelegate'
Hello all, this could surely be a newbie mistake but I'm unable to adopt this protocol to my class object I've created in a new project. The Error: "Cannot find type 'OCKSurveyTaskViewControllerDelegate' in scope" import CareKit import CareKitUI import CareKitStore import ResearchKit import UIKit import os.log final class CareFeedViewController: OCKDailyPageViewController, OCKTaskSurveyViewControllerDelegate { } However, I've been able to locate the 'OCKSurveyViewController.swift" file in the CareKit framework from SPM which has the protocol defined there, but I'm still unable to utilize it. Was the protocol only for demonstration purposes and not for use outside of the WWDC21 - CareKit Code Along?
Replies
1
Boosts
0
Views
1.4k
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
832
Activity
Jun ’23
HealthKit for iPadOS?
This might be a silly question. Does anyone know if HealthKit is available for iPadOS 14? I see that it is now available for MacCatalyst 13.0+ in the documentation but iPadOS was not listed. Thanks, Casey
Replies
3
Boosts
0
Views
2.2k
Activity
Jun ’23
watchOS 9 WidgetKit complications missing com.apple.developer.healthkit entitlement
I have an iOS/wOS app that launched last year. Now I want to add complications to it and use the new way of doing complications with WidgetKit. I have everything in place up to the point where I'm supposed to read the data from Health to display it, where it fails with Missing com.apple.developer.healthkit entitlement. This is the new extension I've added It's embedded in the WatchKit app NOT in the WatchKit Extension and I've added permission to read health data directly in the info.plist for the extension I pull the data from the TimelineProvider protocol method func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> ()) { let currentDate = Date() var entries: [WorkoutEntry] = [] ComplicationHealthManager.loadPreviousWorkouts { workout in let workoutEntry = WorkoutEntry(date: currentDate, workout: workout) entries.append(workoutEntry) let timeline = Timeline(entries: entries, policy: .after(currentDate)) completion(timeline) } } with the help of a small manager class class ComplicationHealthManager: ObservableObject { static func loadPreviousWorkouts(completion: @escaping (HKWorkout?) -> Void) { let healthStore: HKHealthStore = HKHealthStore() let workoutPredicate = HKQuery.predicateForWorkouts(with: .traditionalStrengthTraining) let compound = NSCompoundPredicate(andPredicateWithSubpredicates: [workoutPredicate]) let sortDescriptor = NSSortDescriptor(key: HKSampleSortIdentifierEndDate, ascending: false) let query = HKSampleQuery( sampleType: .workoutType(), predicate: compound, limit: 0, sortDescriptors: [sortDescriptor]) { (query, samples, error) in guard let samples = samples as? [HKWorkout], error == nil else { completion(nil) return } let calendar = Calendar.current let todaysSamples = samples.filter{ calendar.isDateInToday($0.endDate) }.last completion(todaysSamples) } healthStore.execute(query) } } The issue is in the closure for the health query where it returns with no workouts but an error stating Error Domain=com.apple.healthkit Code=4 "Missing com.apple.developer.healthkit entitlement." UserInfo={NSLocalizedDescription=Missing com.apple.developer.healthkit entitlement.} The problem here is I don't understand where and how to add an entitlement for the complication extension or the WatchKit app, as none of them have the option for health. I have a health entitlements set for the iPhone app and the WatchKit Extension.
Replies
2
Boosts
0
Views
1.3k
Activity
Jun ’23
RAW IMU Data stops logging on wrist down
Hello, I'm having a problem on my watchOS app where even though I have instantiated a WKExtendedRuntimeSession the app stops logging IMU data a few seconds after the watch has gone to sleep. This happens on my Apple Watch Series 6, but does not happen on the latest Apple Watch Series 8. CPU usage in both cases does not exceed 70%, so I doubt my app is exceeding the limits thus cancelling the WKExtendedRuntimeSession. To back that up, I am not getting the WKExtendedRuntimeSessionInvalidationReason trigger I was suggested to put in place form the documentation. I have tested a couple of different sample rates, this does not seem to happen with a sample rate as low as 1, but does happen already with a sample rate of 30. Could it be a watch limitation, or am I forgetting something? P.S. I have also set the background mode to physical therapy and ticket the workout processing box.
Replies
0
Boosts
0
Views
1k
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
700
Activity
Jun ’23
Can't run Research and Care App (WWDC Code Along)
Hello everyone, I just started watching the WWDC21 Code Along "Build a Research and Care App, Part 1" and wanted to run the project in Xcode. However, when I clone the Repo with the recommended git clone --recurse-submodule https://github.com/carekit-apple/WWDC21-RecoverApp.git command and open the project, I get the following error: /WWDC21-RecoverApp/Recover Part 1/Recover.xcodeproj This Copy Files build phase contains a reference to a missing file 'ResearchKit.framework'. /WWDC21-RecoverApp/ResearchKit only contains 2 files (CONTRIBUTING.md and LFS-Files). I was wondering how I could get the project up and running and if there are additional steps to take, that I didn't see in the presentation / Github Readme. Thanks!
Replies
3
Boosts
0
Views
2.2k
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
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
974
Activity
Jun ’23
HealthKit on iPad
Is there a reason why neither HealthKit data nor the Health App is available on an iPad? And any suggestions how Apple could be convinced to enable that?
Replies
0
Boosts
0
Views
818
Activity
May ’23
splitTotalEnergy deprecated, is there any replacement?
I would like to use this https://developer.apple.com/documentation/healthkit/hkhealthstore/1614170-splittotalenergy but I saw that it's deprecated. Is there any replacement? Thanks!
Replies
0
Boosts
1
Views
901
Activity
May ’23
Unable to reset fitness data on watch
Have tried several times to reset fitness data. iPhone 12 i os = 16.5 watch, 9.5 series 4
Replies
3
Boosts
0
Views
858
Activity
May ’23