Bog*_*nov 8 sample ios swift healthkit
我添加这样的样本:
var store:HKHealthStore?
date = NSDate()
let type = HKQuantityType.quantityTypeForIdentifier(HKQuantityTypeIdentifierDietaryVitaminA)
quantity = HKQuantity(unit: HKUnit.gramUnitWithMetricPrefix(.Micro), doubleValue: 100)
let sample = HKQuantitySample(type: type, quantity: quantity, startDate: date, endDate: date)
store.saveObject(sample, withCompletion: { (success, error) -> Void in
if(error != nil) {
println("Error saving sample: \(error.localizedDescription)")
}else{
println("Sample saved successfully!")
}
})
Run Code Online (Sandbox Code Playgroud)
当我想删除这个示例时,我执行:
store.deleteObject(sample, withCompletion: {(success, error) -> Void in
if(error != nil) {
println("Error deleting sample: \(error.localizedDescription)")
}else{
println("Sample deleted successfully!")
}
})
Run Code Online (Sandbox Code Playgroud)
并且它返回我:删除样本时出错:找不到对象每次我对startDate和endDate使用相同的'date'.我尝试过let sample = HKQuantitySample(type: type, quantity: quantity, startDate: date, endDate: date, metadata: metadata)元数据的位置let metadata = [HKMetadataKeyExternalUUID:"\(Int64(date.timeIntervalSince1970))"],但也没有成功......
| 归档时间: |
|
| 查看次数: |
2107 次 |
| 最近记录: |