IOS Healthkit HeartRate 样本元数据 HKPrivateHeartRateContext fatal error
<p><p>我在使用 IOS 11、WatchOS 4.0 和 <code>HealthKit</code> 时遇到 fatal error :</p>
<blockquote>
<p>fatal error: *** An error occurred while adding a sample to the
workout: Optional("Invalid metadata key: _HKPrivateHeartRateContext")</p>
</blockquote>
<p>我没有为心率样本设置任何元数据。 </p>
<p>在流式查询中,我将样本类型设置为:</p>
<pre><code>let quantityType = HKObjectType.quantityType(forIdentifier: HKQuantityTypeIdentifier.heartRate)
</code></pre>
<p>在获取流样本后,我将它们保存为:</p>
<pre><code>func saveAddedSamples(_ workout: HKWorkout) {
if !self.heartRateSamples.isEmpty {
self.healthStore.add(self.heartRateSamples,to: workout) { (success: Bool, error: Error?) -> Void in
guard success else {
fatalError("\n *** An error occurred while adding a " +
"sample to the workout: \(String(describing: error?.localizedDescription))")
}
self.heartRateSamples.removeAll()
}
}
}
</code></pre>
<p>有什么想法吗?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>这是 watchOS 4.0 中的一个错误,已在 4.1 中修复。</p></p>
<p style="font-size: 20px;">关于IOS Healthkit HeartRate 样本元数据 HKPrivateHeartRateContextfatal error ,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/46801588/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/46801588/
</a>
</p>
页:
[1]