![](/img/trans.png)
[英]enableBackgroundDelivery Health-kit iOS15 not working correctly
[英]How to get bodyTemperature using health-kit in iOS?
我想在iWatch中获取bodyTemperature,所以下面是我编写的代码
override func willActivate() {
super.willActivate()
guard let type=HKQuantityType.quantityType(forIdentifier: .bodyTemperature) else {
return
}
let dataTypes=Set(arrayLiteral:type)
healthStore.requestAuthorization(toShare: nil, read: dataTypes) { (success, error) in
if success==false{
print("Authorize Unsuccessfull ")
}
}
}
@IBAction func startBtnTapped(){
startSession()
}
func startSession(){
session = HKWorkoutSession(activityType: HKWorkoutActivityType.crossTraining, locationType: HKWorkoutSessionLocationType.indoor)
session?.delegate = self
healthStore.start(session!)
}
func workoutSession(_ workoutSession: HKWorkoutSession, didChangeTo toState: HKWorkoutSessionState, from fromState: HKWorkoutSessionState, date: Date) {
switch toState {
case .running:
if let query=createQuery(date){
healthStore.execute(query)
}
case .ended:
workoutEnd(date)
default:
print("Unexpted state:\(toState)")
}
}
func createQuery(_ startDate:Date)->HKQuery?{
guard let type=HKObjectType.quantityType(forIdentifier: .bodyTemperature) else {
return nil
}
let predicate=getPredicate()
let query=HKAnchoredObjectQuery(type: type, predicate: predicate, anchor: nil, limit: Int(HKObjectQueryNoLimit)) { (query, sample, deletedObject, newAnchor, error) in
print("query:\(query)")
print("sample:\(sample)")
print("deletedObject:\(deletedObject)")
print("newAnchor:\(newAnchor)")
self.updateValues(sample)
}
query.updateHandler={(query,sample,deletedObject,newAcnhor,error) in
self.updateValues(sample)
}
return query
}
每次完成块重新执行0值时执行查询。 相同的代码正在努力获得心率。 我不知道从halthkit获取身体温度,葡萄糖率,bodyFatPercentage,bodyMassIndex等其他东西的程序。 任何人都可以帮助我
提前致谢
Apple Watch上没有体温传感器。 HealthKit中的任何体温样本都已由应用程序保存或由用户手动输入。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.