Post

Replies

Boosts

Views

Activity

Reply to When are inBed logs from the Apple Watch added and what do they mean?
Please confirm that that you and your friend are using the same version of watchOS and are both using the native Apple sleep tracking experience rather than a third party app. "If a user sleeps with their Apple Watch at night with a sleep schedule set up, are CORE, REM and Deep enough to check for asleep status? Or is inBed also necessary?" It depends on the needs of your app. If you're developing an app that is trying to calculate time asleep separate from time in bed you would not want to fetch the inBed samples from HealthKit and just check the asleep samples.
Topic: App & System Services SubTopic: Core OS Tags:
Mar ’23
Reply to Wake up after a certain amount of sleep
Sleep is a publicly readable and writable data type so it depends on the implementation of a given application that writes data. The built in sleep app writes Sleep data at the end of the night as you've seen. Other apps may choose to behave differently depending on their sleep algorithm implementations. I hope that answers your question.
Aug ’22
Reply to Calculate daily steep from healthkit data
I'm not sure exactly what you mean by "merging data for consecutive days" but I suspect you're querying for "what is the total amount of sleep time in this calendar day" which will include data from both the night you care about but also the morning corresponding to the night before and that's what you mean by merged. You'll likely want to query a little differently. For example, instead of bucketing by a midnight to midnight day, bucket by a 6pm - 6pm bounded day. Or apply some other type of processing to determine which "actual" day sleep data belongs to.
May ’22
Reply to Sleep Samples sum off by 2 minutes
A “sleep day” runs from 6pm-6pm so some “naps” between 3pm and 6pm could perhaps help contribute to some differences between what’s reported in Health.
Replies
Boosts
Views
Activity
Mar ’25
Reply to Access Data Source from Apple HealthKit API
Check out https://developer.apple.com/documentation/healthkit/hkobject/1615483-sourcerevision
Replies
Boosts
Views
Activity
Feb ’24
Reply to HKCategoryValueSleepAnalysis Sending incorrect sleep data.
Do any of the samples overlap? If so you'll be counting too much. Are any of the samples logged as asleepUnspecified? If so, you've forgotten to count them. It's also not clear what date you're passing in to start looking back from. You're just fetching the last 24 hours but the dates in the Health app are based from 6pm-6pm.
Replies
Boosts
Views
Activity
Jan ’24
Reply to How can I get non-overlapping sleep samples from HealthKit in Swift?
Hello, if your device contains overlapping in bed intervals from multiple source then that's what the query will return. It will be up to you to decide how you want to handle it. You could ignore certain sources if you want, for example. Or you can keep track of the intervals yourselves in some kind of data structure.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
May ’23
Reply to When are inBed logs from the Apple Watch added and what do they mean?
Please confirm that that you and your friend are using the same version of watchOS and are both using the native Apple sleep tracking experience rather than a third party app. "If a user sleeps with their Apple Watch at night with a sleep schedule set up, are CORE, REM and Deep enough to check for asleep status? Or is inBed also necessary?" It depends on the needs of your app. If you're developing an app that is trying to calculate time asleep separate from time in bed you would not want to fetch the inBed samples from HealthKit and just check the asleep samples.
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Mar ’23
Reply to Retrieve sleep schedule bedtime and wake up times
No that's available through HealthKit. You can set up shortcuts that trigger at bedtime/wakeup/etc however.
Replies
Boosts
Views
Activity
Feb ’23
Reply to HealthKit sleep analysis
You can use allAsleepValues in your query: https://developer.apple.com/documentation/healthkit/hkcategoryvaluesleepanalysis/3931475-allasleepvalues HKCategoryValueSleepAnalysis.predicateForSamples(equalTo: .allAsleepValues)
Replies
Boosts
Views
Activity
Feb ’23
Reply to Wake up after a certain amount of sleep
Sleep is a publicly readable and writable data type so it depends on the implementation of a given application that writes data. The built in sleep app writes Sleep data at the end of the night as you've seen. Other apps may choose to behave differently depending on their sleep algorithm implementations. I hope that answers your question.
Replies
Boosts
Views
Activity
Aug ’22
Reply to watch os 9 sleep analysis is not accurate as health app
Hello, From the look at your query it seems like you're fetching all REM samples in the health database where in your screenshot it appears you're looking at just one day of data. Perhaps that's the discrepancy you're seeing? Thanks
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Jun ’22
Reply to Calculate daily steep from healthkit data
I'm not sure exactly what you mean by "merging data for consecutive days" but I suspect you're querying for "what is the total amount of sleep time in this calendar day" which will include data from both the night you care about but also the morning corresponding to the night before and that's what you mean by merged. You'll likely want to query a little differently. For example, instead of bucketing by a midnight to midnight day, bucket by a 6pm - 6pm bounded day. Or apply some other type of processing to determine which "actual" day sleep data belongs to.
Replies
Boosts
Views
Activity
May ’22