我試圖讓bodyTemperature在IWATCH所以下面是我寫如何在iOS中使用健康工具包獲取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等其他東西的程序。任何人可以幫助我在這
在此先感謝
你期望得到什麼樣品?什麼應用程序保存它們 – Allan
@Allan我想要獲取healthstore中可用的樣本。基本上我在iWatch中嘗試它。 – Rafeeq
@Allan我也想知道我們可以使用手錶傳感器獲得什麼。我做了一些谷歌關於這個,但不成功請引導我在這 – Rafeeq