SpeedySloth의 Apple 샘플 코드를 사용하여, 시뮬레이터에서 심박수 샘플을 얻었지만 Series 0 Apple Watch에서 WatchOS 4.1을 실행하는 샘플을 얻지 못했습니다. 이거 버그 야? 이 문제가 발생한 사람은 누구입니까?WatchOS 4는 심박수 샘플을받지 못하고 있습니까?
코드 :
func startHeartRateQuery(from startDate: Date, updateHandler: @escaping ([HKQuantitySample]) -> Void) {
let typeIdentifier = HKQuantityTypeIdentifier.heartRate
startQuery(ofType: typeIdentifier, from: startDate) { _, samples, _, _, error in
guard let quantitySamples = samples as? [HKQuantitySample] else {
print("Heart rate query failed with error: \(String(describing: error))")
return
}
print("heartRate samples = \(quantitySamples)")
updateHandler(quantitySamples)
}
}
//Generic helper function
private func startQuery(ofType type: HKQuantityTypeIdentifier, from startDate: Date, handler: @escaping
(HKAnchoredObjectQuery, [HKSample]?, [HKDeletedObject]?, HKQueryAnchor?, Error?) -> Void) {
let datePredicate = HKQuery.predicateForSamples(withStart: startDate, end: nil, options: .strictStartDate)
let devicePredicate = HKQuery.predicateForObjects(from: [HKDevice.local()])
let queryPredicate = NSCompoundPredicate(andPredicateWithSubpredicates:[datePredicate, devicePredicate])
let quantityType = HKObjectType.quantityType(forIdentifier: type)!
let query = HKAnchoredObjectQuery(type: quantityType, predicate: queryPredicate, anchor: nil,
limit: HKObjectQueryNoLimit, resultsHandler: handler)
query.updateHandler = handler
healthStore.execute(query)
activeDataQueries.append(query)
}
귀하의 질문이 너무 광범위합니다. 질문은 질문 자체의 정보와 코드를 기반으로 답할 수 있어야합니다. – tambre
요점은 시뮬레이터 데이터를 얻고 있기 때문에 코드가 정확하다는 것입니다. 다른 사람들이 같은 문제를 겪고 있는지 더 묻고 있습니다. https://forums.developer.apple.com/message/272553#272553 또는 내 장치 – GarySabo