使用healthKit框架,我尝试在健康应用程序中读取我的iPhone和Apple手表的步数。但是当我查询HKQuantitySample
HKDevice
个对象时,它没有显示localIdentifier
和UDIDeviceIdentifier
。
知道为什么他们是空的吗?
是因为来源没有记录信息?
请求
func getFitness() {
let stepsCount = HKQuantityType.quantityTypeForIdentifier(
HKQuantityTypeIdentifierStepCount)
let stepsSampleQuery = HKSampleQuery(sampleType: stepsCount!,
predicate: nil,
limit: 10000,
sortDescriptors: nil) {
(query, results, error) in
if let results = results as? [HKQuantitySample] {
for result in results {
print("device: \(result.device) steps:\(result)" )
}
}
}
self.healthStore?.executeQuery(stepsSampleQuery)
}
回复
device: <<HKDevice: 0x14e238380>, name:iPhone, manufacturer:Apple, model:iPhone, hardware:iPhone7,1, software:9.2.1> steps:63 count "iPhone6plus" (9.2.1) "iPhone" 2016-03-31 09:11:13 +0800 2016-03-31 09:11:58 +0800
device: <<HKDevice: 0x14e2385a0>, name:Apple Watch, manufacturer:Apple, model:Watch, hardware:Watch1,1, software:2.1> steps:15 count "Apple Watch" (2.1) "Apple Watch" 2016-03-31 11:15:23 +0800 2016-03-31 11:15:31 +0800
答案 0 :(得分:0)
HealthKit for iPhone和Apple Watch来源未记录localIdentifier
和UDIDeviceIdentifier
。