我正在调查研究工具包和健康工具包。在模拟器上进行明智的测试,我没有任何数据量大的问题:)
如何将数据(更具体地说是步骤)放入HealthKit商店?下面是我得到的结果,它看起来没有失败,但在Health app仪表板中没有显示任何内容。我希望这能提供14天的数据...
var date:NSDate! = NSDate()
let calendar: NSCalendar! = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)
let dateComponents = NSDateComponents()
dateComponents.day = -13
let endingDate:NSDate! = calendar.dateByAddingComponents(dateComponents, toDate: date, options: NSCalendarOptions())
while date.compare(endingDate) != NSComparisonResult.OrderedAscending {
let countRate = Double(arc4random_uniform(500) * arc4random_uniform(10))
let stepsUnit = HKUnit.countUnit()
let quantity = HKQuantity(unit: stepsUnit, doubleValue: countRate)
let dateComponents = NSDateComponents()
dateComponents.day = -1
date = calendar.dateByAddingComponents(dateComponents, toDate: date, options: NSCalendarOptions())
let sample = HKQuantitySample(type: HKQuantityType.quantityTypeForIdentifier(HKQuantityTypeIdentifierStepCount)!, quantity: quantity, startDate: date, endDate: date)
HKHealthStore().saveObject(sample, withCompletion: { (success, error) -> Void in
if let _ = error {
print("Error saving sample: \(error!.localizedDescription)")
}
})
}发布于 2016-04-30 00:57:00
忽略我这似乎起作用了。您需要进入"Health Data“选项卡,基本上选择您想要的任何内容(在本例中为Fitness > Steps),它将显示所有数据!
你也可以选择在仪表板上显示选项卡,这样应用程序的初始启动就不会看起来是空的!
我将把这篇文章留给那些想要迷你代码样本的人,如果他们遇到不知道数据可以显示在哪里的人!
https://stackoverflow.com/questions/36942449
复制相似问题