iOS WatchOS5 - 如何以特定的时间间隔以编程方式检测Apple Watch是否在手腕上(佩戴)?

问题描述 投票:1回答:1

我很感兴趣,如果有一些HealthKit或其他数据源,我可以查询Apple Watch是否在给定的时间间隔内佩戴/接触手腕。目前我依赖HeartRit的HealthKit查询,看来如果我在某个窗口内没有心率读数,那么手表很可能不在手腕或充电。

有没有更好的方法来检测Apple Watch是否戴在手腕上?

这种方法的问题在于它不是很具描述性 - 如果用户在最后一分钟戴上手表并进行测量,这个逻辑会将整个时期视为手表“开启”。还有更好的东西吗?

// obtain heartRateSamples from HealthKit and filter them
let hrFilterStart = startDate.addingTimeInterval(startSecondsOffset)
let hrFilterEnd = hrFilterStart.addingTimeInterval(Double(30 * 60) )

let heartRateDuringTimeSlice =  heartRateSamples.filter{ sample -> Bool in
    let fallsBetween = (hrFilterStart ... hrFilterEnd).contains(sample.startDate)
    return fallsBetween
}

if heartRateDuringTimeSlice.count == 0 {
    //watch is not on the wrist - probably charging, ignore this interval
}
swift health-kit watch-os-5
1个回答
1
投票

HealthKit不会公开您可以用来可靠地确定Apple Watch是否在手腕上的任何信息。使用心率或其他自动收集的样本可以很好地适用于大多数用户,但请记住,即使手表在手腕上,也有可能无法以一致的频率收集心率样本。

© www.soinside.com 2019 - 2024. All rights reserved.