Reputation: 100
I know that HealthKit can retrieve sleep states based on some samples given start and end time. But I wonder if it can give a current realtime status of the sleep state, meaning just retrieving the current state instead. Or is it using some algorithm and this requires several values and that's why all I can find is about taking samples with some time gap in middle?
let sleepSampleType = HKCategoryType(.sleepAnalysis)
let sleepCategory = HKCategoryValueSleepAnalysis.asleepDeep.rawValue
let deepSleepSample = HKCategorySample(type: sleepSampleType,
value:sleepCategory,
start: startDate,
end: endDate)
Upvotes: 2
Views: 813
Reputation: 411
Sleep stages data is not available in real-time. You can only read it after the user wakes up and the samples are written.
Upvotes: 2