私はAppleのHealthKitを使用するSwift 4でアプリを書いています。私は "VO2 Max"メトリックに書き込もうとしていますが、使用する単位がわかりません。 Health App自体では、ユニットは「mL /(kg * min)」と表示されていますが、Appleのマニュアルhereにはそのようなものは表示されません。私のコードはこのように見えます。私は何の代わりに置くべきですか??? 2行目?VO2の最大測定にはどのようなタイプのHealthKitユニットが使用されていますか? - Swift 4
writeHKMetric = HKQuantityType.quantityType(forIdentifier: HKQuantityTypeIdentifier.vo2Max)!
writeHKQuantity = HKQuantity.init(unit: HKUnit.???, doubleValue: 1)
(に書き込むためのコード、参考として、サイクリングの距離は次のようになり、言う。 "HKUnit.mileを()" に注意してください)
writeHKMetric = HKQuantityType.quantityType(forIdentifier: HKQuantityTypeIdentifier.distanceCycling)!
writeHKQuantity = HKQuantity.init(unit: HKUnit.mile(), doubleValue: 1)
私は別のメトリックを使用しようとすると、 数を言って、私はこのエラーを取得:
2017-12-14 22:08:01.876935-0500 Stand Hours 2.0[478:76005] *** Terminating app due to uncaught exception '_HKObjectValidationFailureException', reason: 'HKQuantitySample 1 count (2017-12-08 08:00:00 -0500 - 2017-12-08 08:00:00 -0500) requires unit of type Volume/Mass·Time. Incompatible unit: count'
をしかし、私は私のユニットに「ボリューム/質量*タイム」を設定する方法がわかりません。
あなたはまた、単にユニットをこのようにインスタンス化することができます: let unit = HKUnit(from: "mL/min・kg") – Allan