HealthKit

RSS for tag

Access and share health and fitness data while maintaining the user’s privacy and control using HealthKit.

HealthKit Documentation

Posts under HealthKit tag

109 Posts
Sort by:
Post not yet marked as solved
0 Replies
146 Views
Hey! TLDR: How Health app knows the new menstruation cycle started? The API Adding .menstrualFlow (HKCategoryValueMenstrualFlow) samples require HKMetadataKeyMenstrualCycleStart: Bool parameter. It's fairly simple for the consecutive days - the first sample includes true, the rest false. The problem What about more complex scenarios like: 3 days of unspecified samples, then 2 days of none samples, and unspecified sample again. Should it be marked as the new cycle start? I don't want to prompt the user to confirm the new menstruation cycle. Observations I noticed Health app performs some logic under the hood. For instance, when I marked 5 days in a row unspecified, then left 6 days in a row empty, then selected unspecified again, I got 2 menstruation cycles (11 days ago and today). But when I changed the number of the days I marked as unspecified before the gap, or the length of the gap, or edited the cycles further in the past, I ended up having just 1 menstruation cycle. I guess Health app takes into consideration: previous menstruation length, gap length, average cycle length. But what is the exact math here? I don't want to ruin the user's statistics 💚 I found in the user guide this info about the fertility: The fertile window will be the six days you're most likely to be fertile, based on data that you’ve logged about your period or a positive ovulation test result. The fertile window prediction is based on a traditional calendar method. The fertile window is calculated by subtracting 13 days (the luteal phase) from the estimated next cycle start date. So I think something similar might be going on here. Thanks in advance!
Posted Last updated
.
Post not yet marked as solved
0 Replies
96 Views
Hello, I want to build an app that will allow the user to entry some health related records and be synced with the HealthKit. Any record that is in the HealthKit is stored locally on the device. I find it conceptually unsure if I should be storing the HealthKit records in the SwiftData to make the user records available across the iCloud synced devices. Should I read the HealthKit record, make a copy of it (including it's ID) on my app's data in SwiftData? How the syncing should be done the right way? thanks.
Posted Last updated
.
Post not yet marked as solved
0 Replies
114 Views
Hello Do we have access to the ECG raw data on the apple watch? I was able to access the data using HKElectrocardiogram Class API. "ecgSample" returns all the recorded ECG logs done by the user using the default apple app. I want to access the data in real-time, do the API supports that? That is, I want to create a custom app in which I direct the user towards recording an ecg signal and then do whatever I want with it. Please let me know, that would be very helpful!
Posted
by zein95.
Last updated
.
Post not yet marked as solved
0 Replies
175 Views
I'm looking at a swimming workout sample and in the metadata I see: Optional(["HKIndoorWorkout": 0, "HKSwimmingLocationType": 2, "HKAverageMETs": 10.7366 kcal/hr·kg, "HKTimeZone": America/New_York]) There is no mention of the HKMetadataKeySwimmingStrokeStyle yet when I look at the workout in the Apple Fitness app, there is stroke style data. How can I access the stroke enum?
Posted
by AndrewH.
Last updated
.
Post not yet marked as solved
0 Replies
161 Views
I'm looking to access the HKMetadataKeyWeatherCondition that indicates the weather during a workout (sunny, cloudy, rain, etc.). I have accessed the workout metadata where I can see temperature and humidity but the weather enum eludes me. Any help would be appreciated.
Posted
by AndrewH.
Last updated
.
Post not yet marked as solved
0 Replies
104 Views
When I record a workout with iPhone, the workout is displayed in the exercise ring. But not with iPad. A workout from iPad is recorded, it is in "Health" app history, but the exercise ring does not display it. Why is the workout not displayed on the exercise ring on iPad?
Posted Last updated
.
Post not yet marked as solved
0 Replies
203 Views
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.
Posted
by steve23.
Last updated
.
Post not yet marked as solved
0 Replies
179 Views
Hi, I can find no way of getting HKSeriesType.heartbeat() data from the health store using my own workout app. The values captured seem to be from the irregular HRV measurements done by Apple. There is a video showing HKHeartbeatSeriesSamples being consumed in an app but not how to capture them from the optical sensor. The WWDC video on this https://stackoverflow.com/questions/77950041/getting-heartbeatseriessamples-in-ios-swift-healthkit-hkanchoredobjectquery at around 28 mins assumes you have written the beats from an external device - not from the optical sensor. I have set typesToRead to be: // Beat addition HKSeriesType.heartbeat(), HKQuantityType.quantityType(forIdentifier: .heartRateVariabilitySDNN)!, // end beat addition Why is the watch app not saving beat to beat interval series to the health store?? Failing that how can the watch app access the data itself so that it can then forward to the companion iPhone app? Help much appreciated.
Posted Last updated
.
Post not yet marked as solved
1 Replies
209 Views
I am reading sleep data from AppleHealthKit API that have wearables connected. Is it possible to retrieve: If data came from wearable (e.g.--> True/False) Wearable brand / Model (e.g. apple or Applewatch2) Software Version (e.g. 1.3.4) Are there specific permissions that need to be asked to retrieve source data?
Posted
by ATGLH.
Last updated
.
Post not yet marked as solved
0 Replies
167 Views
When obtaining the running data of the Apple Watch in the health App, the segmented average heart rate obtained is inconsistent with the data displayed in the health App. Have you encountered it?
Posted Last updated
.
Post not yet marked as solved
1 Replies
211 Views
The edited code still has the problem of not lining up with the health app private func fetchSleepData(for date: Date) { let sleepType = HKObjectType.categoryType(forIdentifier: .sleepAnalysis)! let endOfPeriod = date let startOfPeriod = Calendar.current.date(byAdding: .day, value: -1, to: endOfPeriod)! let predicate = HKQuery.predicateForSamples(withStart: startOfPeriod, end: endOfPeriod, options: [.strictStartDate, .strictEndDate]) let query = HKSampleQuery(sampleType: sleepType, predicate: predicate, limit: HKObjectQueryNoLimit, sortDescriptors: nil) { query, samples, error in guard let samples = samples as? [HKCategorySample], !samples.isEmpty else { DispatchQueue.main.async { self.inBedTime = 0 self.coreTime = 0 self.deepTime = 0 self.remTime = 0 self.isSleepDataAvailable = false } print("No sleep data available for date: \(date)") return } print("Fetched \(samples.count) sleep samples for date: \(date)") var inBedTime = 0.0 var asleepTime = 0.0 var deepTime = 0.0 var remTime = 0.0 for sample in samples { print("Sample value: \(sample.value)") let duration = sample.endDate.timeIntervalSince(sample.startDate) / 60 // convert to minutes switch sample.value { case HKCategoryValueSleepAnalysis.inBed.rawValue: inBedTime += duration case HKCategoryValueSleepAnalysis.asleepCore.rawValue: coreTime += duration case HKCategoryValueSleepAnalysis.asleepDeep.rawValue: deepTime += duration case HKCategoryValueSleepAnalysis.asleepREM.rawValue: remTime += duration default: break } } DispatchQueue.main.async { self.inBedTime = inBedTime self.coreTime = coreTime self.deepTime = deepTime self.remTime = remTime self.isSleepDataAvailable = true } } healthStore?.execute(query) }
Posted
by TechyGod.
Last updated
.
Post not yet marked as solved
0 Replies
217 Views
I'm thinking about developing a workout tracking app. To avoid the issue of having to repeatedly download workouts, I want to persist some app model data like Apple does with their Fitness App. At a minimum, the HKWorkout class. Has anyone seen this done before? I'd hate to have reinvent the wheel. HKWorkout: HKSample: HKObject: NSObject.
Posted
by AndrewH.
Last updated
.
Post not yet marked as solved
0 Replies
248 Views
Hello all, I'm trying to build a watch app for a research study built around heart rate. Currently I have built a IOS app with a companion watchOS app for a firebaseDatabase connection. There are two remaining goals of this project that include the following: While the watch app is in the background or when it's closed, is it possible for the apple watch to send a notification to the user if per say the user's heart rate goes over a custom threshold of 70bpm? If so, how should this be implemented, and can the app be consistently monitoring the heart rate to get accurate realtime notifications, or is does apple limit background updates to periodically? For this study, we want to analyze if user's actually open the watchapp because of the notifications. Is it possible to record data / track user interactions from the notifications? If so, what kind of data can be tracked and how can it be stored?
Posted
by bduong21.
Last updated
.
Post not yet marked as solved
1 Replies
332 Views
hello We are currently developing using Healthkit. Starting with xcode15, healthkit throws an error. The code causing the error is HKQuantityType(.stepCount). When I use this code An EXC_BAD_ACCESS (code=1, address=0x0) error occurs. The error is: AppDelegate It also appears when I call didFinishLaunchingWithOptions. Is the linker the problem? Or is the Swift version the problem? Or HealthKit? Cleaning and initializing DerivedData I also tried downgrading DriverKit 22.4, but the error still appears. Please tell me how to solve this problem. Test model information is as follows: -iPhone 14 Pro iOS 16.5.1
Posted Last updated
.
Post not yet marked as solved
0 Replies
241 Views
hello After updating to xcode 15.1 while using xcode 14.3, I keep getting EXC_BAD_ACCESS (code=1, address=0x0) in HealthKit's HKQuantityType(.stepCount). We also created and tested HKQuantityType(.stepCount) in the appDelegate class. But it comes out the same as above. I think there has been a change in library building and linking starting from xcode15. Please guide me what to do about this problem. The test model is iphone 14 pro It's 16.5.1.
Posted Last updated
.
Post not yet marked as solved
0 Replies
335 Views
Errors: ''Invalid info.plist key. The key 'NSHealthShareUsageDescription'' ''Invalid info.plist key. The key 'NSHealthUpdateUsageDescription'' The app works fine when I just run it on hardware without deployment, but as soon as I try to distribute it, this shows up. The keys above are both defined and described in my App and extensions lists, so what's wrong?
Posted
by ksinha.
Last updated
.
Post not yet marked as solved
1 Replies
340 Views
Our app uses HKWorkoutSession after some actions, to keep app on high priority in background and to keep Apple Watch returns to our app when the watch is waked up. We don't collect or register any activity record. But for some reasons, some users reviewed our app saying that when they're using our app, the Workout app on Apple Watch seems to be affected, ex: Move and exercises is recorded as an abnormal/impossible value... . Is this possible? I don't see any document mention this side effect?
Posted
by rainberry.
Last updated
.
Post not yet marked as solved
0 Replies
259 Views
I have the same issues, when i use HKStatisticsCollectionQuery query user step count, there's a big difference in the number of steps I'm query before and after a minute's interval. 2023-12-17 15:45:41 steps=529 2023-12-17 15:46:52 steps=5817 2023-12-19 19:43:59 steps=2680 2023-12-19 19:44:31 steps=5554 What is causing this issue? I would like some assistance, please.
Posted Last updated
.
Post not yet marked as solved
0 Replies
344 Views
With the recent iPad OS 17 release, Apple added the Health app for the first time. Looking at it, it seems pretty similar to the phone version as the Health app only shows 'historical' health data. My question is this: We are developing an iPad based fitness app. Is there any way of getting real-time health data from the Apple Watch directly to an iPad app? (basically, we just need heart rate). Or, do we have create some sort of workflow through the Phone like Watch -> iPhone running our app -> our servers -> iPad running our app ..to get that real-time data? We really just want Watch -> iPad running our app. I'm afraid I already know the answer but just thought I'd check in case I'm missing something in iOS 17. Thanks!
Posted Last updated
.
Post not yet marked as solved
0 Replies
293 Views
Hello, it is discussed here https://developer.apple.com/videos/play/wwdc2023/10016/ (12:16) regarding WorkoutComposition, but unfortunately, I cannot find this class or structure in the documentation. Has this concept been removed?
Posted
by zikomiko.
Last updated
.