Dav*_*iri 2 ios swift healthkit ios11 xcode9.4
我正在尝试读取 HKWorkout 的路线数据,但我无法读取,因为当我尝试HKWorkoutRouteQuery使用检索到的样本实例化 an 时,我的编辑器中出现错误,提示“传递给调用的参数不带任何参数” 。
根据Apple 的文档,我的代码如下所示:
func getRouteData() -> [(Double)] {
// Return early if not a distance workout
guard self.shouldShowDistance else {
return []
}
let store = HKHealthStore()
let runningObjectQuery = HKQuery.predicateForObjects(from: self.workout)
let routeQuery = HKAnchoredObjectQuery(type: HKSeriesType.workoutRoute(), predicate: runningObjectQuery, anchor: nil, limit: HKObjectQueryNoLimit) { (query, samples, deletedObjects, anchor, error) in
guard error == nil else {
// Handle any errors here.
fatalError("query failed")
}
guard samples != nil else {
fatalError("No samples")
}
guard samples!.count > 0 else { fatalError("No samples") }
guard let route = samples?.first as? HKWorkoutRoute else {
fatalError("No samples")
}
// Create the route query.
let query = HKWorkoutRouteQuery(route: route) { (query, locationsOrNill, done, errorOrNil) in
// This block may be called multiple times.
if let error = errorOrNil {
// Handle any errors here.
return
}
guard let locations = locationsOrNil else {
fatalError("*** Invalid State: This can only fail if there was an error. ***")
}
// Do something with this batch of location data.
if done {
// The query returned all the location data associated with the route.
// Do something with the complete data set.
}
// You can stop the query by calling:
// store.stop(query)
}
store.execute(query)
}
store.execute(routeQuery)
return []
}
Run Code Online (Sandbox Code Playgroud)
这对我来说毫无意义,因为 Apple 自己的文档要求使用示例实例化 HKWorkoutRouteQuery。
任何帮助将非常感激。非常感谢。
Apple 通过 Bug Reporter 回复了我。问题是我忽略了导入 CoreLocation。您可以通过将以下行添加到文件顶部来修复此错误。
import CoreLocation
Run Code Online (Sandbox Code Playgroud)
顺便说一句,我认为这是编写描述性错误重要性的一个很好的例子。如果错误提到了有关结果完成需要的内容CoreLocation,我本可以自己解决这个问题。
| 归档时间: |
|
| 查看次数: |
294 次 |
| 最近记录: |