具有空localIdentifier和UDIDeviceIdentifier的HKDevice

时间:2016-03-31 14:16:49

标签: ios iphone cocoa-touch health-kit

使用healthKit框架,我尝试在健康应用程序中读取我的iPhone和Apple手表的步数。但是当我查询HKQuantitySample HKDevice个对象时,它没有显示localIdentifierUDIDeviceIdentifier。 知道为什么他们是空的吗? 是因为来源没有记录信息?

请求

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

1 个答案:

答案 0 :(得分:0)

HealthKit for iPhone和Apple Watch来源未记录localIdentifierUDIDeviceIdentifier