Is sleep analysis data available in Smart Alarms?

I am working on a Smart Alarm app for Watch OS.

When testing on an Series 10 watch, I am successfully able to read heart rate data in the ExtendedRuntimeSession. However, although the calls succeed, the sleep analysis data is all 0.

The app successfully gets authorization for: [HKQuantityType(.heartRate), HKObjectType.categoryType(forIdentifier: .sleepAnalysis)!]

I have read that sleep data is not available for less than an hour time period. The Smart Alarm extended session has a 30 minute limit.

Does that mean it is not possible to read sleep analysis data in a Smart Alarm extended session?

Thank you!

Answered by DTS Engineer in 822381022

Would you mind to describe how you test the behavior then and with what version of watchOS?

Note that if the period of time the user is detected to be at rest is shorter than an hour, HealthKit won't generate any sleep analysis samples.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Is it that the system doesn't generate the .sleepAnalysis samples in that duration, or that the samples are there but your app doesn't have the access when it runs in an extended runtime session (WKExtendedRuntimeSession)?

For the former, do you check with Health.app on the paired iPhone if there is any sleep data there? For the latter, do you confirm that you can read the data when your watchOS app runs in the foreground with the same code? Assuming that the authorization is successfully done, it will be a surprise to me if you can read the .heartRate samples but not the .sleepAnalysis samples.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Thank you. The system doesn't generate the .sleepAnalysis samples in that duration. There was no sleep data saved in the Health.app for the test.

I tried changing the Sleep bed time to be before the testing window, but still no data was saved in the 30 minute extended session window.

Is there a way to programmatically force sleepAnalysis to be collected in a 30 minute window?

Accepted Answer

Would you mind to describe how you test the behavior then and with what version of watchOS?

Note that if the period of time the user is detected to be at rest is shorter than an hour, HealthKit won't generate any sleep analysis samples.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Thanks for confirming that. sleep analysis work for my use case then. I’ll use heart rate and accelerometer only.

^won‘t work

Is sleep analysis data available in Smart Alarms?
 
 
Q