Post not yet marked as solved
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!
Post not yet marked as solved
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.
Post not yet marked as solved
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!
Post not yet marked as solved
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?
Post not yet marked as solved
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.
Post not yet marked as solved
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?
Post not yet marked as solved
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.
Post not yet marked as solved
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.
Post not yet marked as solved
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?
Post not yet marked as solved
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?
Post not yet marked as solved
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)
}
Post not yet marked as solved
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.
Post not yet marked as solved
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?
Post not yet marked as solved
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
Post not yet marked as solved
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.
Post not yet marked as solved
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?
Post not yet marked as solved
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?
Post not yet marked as solved
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.
Post not yet marked as solved
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!
Post not yet marked as solved
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?