本文介绍了iOS WatchOS5-如何以编程方式检测Apple Watch是否在特定时间间隔戴在手腕上(磨损)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很感兴趣是否有一些HealthKit或其他数据源,我可以查询这些数据来了解Apple Watch在给定的时间间隔内是否戴在手腕上或与手腕接触.当前,我依靠HealthKit查询获取HeartRate,看来如果在某个窗口内没有心率读数,则手表很可能不在手腕上或正在充电.

是否有更好的方法来检测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
}
解决方案

HealthKit不会公开可用于可靠确定Apple Watch是否在手腕的任何信息.使用心率表或其他自动收集的样本可以满足大多数用户的需求,但是请记住,即使在佩戴手表的情况下,也有可能无法以一致的频率收集心率样本. >

I'm interested if there is some HealthKit or other data source I can query to know if the Apple Watch was worn/in contact with the wrist at a given time interval. Currently I'm relying on HealthKit query for HeartRate and it appears that if I get no heart rate readings within a certain window, then the watch was most likely off the wrist or charging.

Is there a better way to detect if the Apple Watch was worn on the wrist?

The problem with this method is that it is not very descriptive - if the user put on the watch at the last minute and got a measurement, this logic would consider the entire period as having the watch "On". Is there something better?

// 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
}
解决方案

HealthKit does not expose any information that you can use to reliably determine whether the Apple Watch was on-wrist. Using the presence of heart rate or other automatically collected samples will work well enough for most users, but keep in mind that there are situations where heart rate samples might not be collected at a consistent frequency even when the watch is on-wrist.

这篇关于iOS WatchOS5-如何以编程方式检测Apple Watch是否在特定时间间隔戴在手腕上(磨损)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 07:40