-1
私は正常にHealthKitに書き込むことができましたが、これらの値を受け取ると常に0が返されます。最新の体重値を返そうとしています。速報を使用してHealthKitで毎回数値0が返されていますか?
これは私が体重を読む機能である:
public func readWeight(result: @escaping (Double) -> Void) {
print("Weight")
let quantityType = HKQuantityType.quantityType(forIdentifier: HKQuantityTypeIdentifier.bodyMass)
let weightQuery = HKSampleQuery(sampleType: quantityType!, predicate: nil, limit: 1, sortDescriptors: nil) {
query, results, error in
if (error != nil) {
print(error!)
result(0.0)
}
guard let results = results else {
print("No results of query")
result(0.0)
return
}
if (results.count == 0) {
print("Zero samples")
result(0.0)
return
}
guard let bodymass = results[0] as? HKQuantitySample else {
print("Type problem with weight")
result(0.0)
return
}
result(bodymass.quantity.doubleValue(for: HKUnit.pound()))
}
healthKitStore.execute(weightQuery)
}
これは、私はそれを変数に設定する方法です:
readWeight() { weight in
Weight = weight
}
ありがとう!
[最新のHKSampleQueryデータポイントをswift 3で入手できますか?](https://stackoverflow.com/questions/44849723/get-the-latest-hksamplequery-datapoint-in-swift-3) – ninjaproger
@ninjaproger私はそれを作った...質問を少し明確にすることができるようにしました。別の質問があります。 – arodebaugh
@arodebaugh両方の質問で同じ問題がある場合は、最初のものを更新して別のものを開いてはいけません開いた。 – Cristik