Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/162.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 实时心率记录时间间隔-WatchOS_Swift_Watchos - Fatal编程技术网

Swift 实时心率记录时间间隔-WatchOS

Swift 实时心率记录时间间隔-WatchOS,swift,watchos,Swift,Watchos,我已经创建了一个带有实时心率记录的手表应用程序,为此我使用了训练课程和HKAnchoredObjectQuery获取结果。在这篇文章中,苹果提到,每5秒更新一次心率值,但在我的例子中,更新最多需要5-10秒。我正在使用watch Severy 3,我需要每5秒收集一次数值 func startWorkout(){ 如果(会话!=nil){ 返回 } 让workoutConfiguration=HKWorkoutConfiguration() workoutConfiguration.activi

我已经创建了一个带有实时心率记录的手表应用程序,为此我使用了训练课程和HKAnchoredObjectQuery获取结果。在这篇文章中,苹果提到,每5秒更新一次心率值,但在我的例子中,更新最多需要5-10秒。我正在使用watch Severy 3,我需要每5秒收集一次数值

func startWorkout(){
如果(会话!=nil){
返回
}
让workoutConfiguration=HKWorkoutConfiguration()
workoutConfiguration.activityType=.walking
workoutConfiguration.locationType=.outdoor
做{
会话=尝试HKWorkoutSession(healthStore:healthStore,配置:workoutConfiguration)
会话?.delegate=self
}抓住{
打印(“无法创建训练课程!”)
}
会话?.startActivity(带:Date())
}
func开始ArtRateStreamingQuery(\uWorkoutStartDate:Date){
guard let quantityType=HKObjectType.quantityType(forIdentifier:HKQuantityTypeIdentifier.heartRate)else{return nil}
让datePredicate=HKQuery.predicateForSamples(具有开始:workoutStartDate,结束:nil,选项:.StreetEndDate)
let predicate=NSCompoundPredicate(和PredicateWithSubpredicates:[datePredicate])
让heartRateQuery=HKAnchoredObjectQuery(类型:quantityType,谓词:谓词,锚点:nil,限制:Int(HKObjectQueryOnlimit)){(查询,sampleObjects,deletedObjects,newAnchor,error)->中的Void
self.updateHeartate(sampleObjects)
}
heartRateQuery.updateHandler={(查询、样本、删除对象、新锚定、错误)->Void in
self.updateHeartate(示例)
}
healthStore.execute(heartRateQuery)
}
func updateheartate(u样本:[HKSample]?){
guard let heartRateSamples=样本为?[HKQuantitySample]else{return}
适用于HeartRate样本中的样本{
让timeStamp=sample.startDate
让值=样本数量
打印(“\(时间戳)\(值)”)
}
}

你能展示一下你目前拥有的代码吗?@aheze我已经更新了我的代码。