tôi thêm mẫu như thế này:Xóa thêm mẫu trong App Sức khỏe
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!")
}
})
Và khi tôi muốn xóa mẫu này tôi thực hiện:
store.deleteObject(sample, withCompletion: {(success, error) -> Void in
if(error != nil) {
println("Error deleting sample: \(error.localizedDescription)")
}else{
println("Sample deleted successfully!")
}
})
Và nó trả tôi: Lỗi xóa mẫu: đối tượng không tìm thấy Mỗi lần tôi sử dụng cùng một 'ngày' cho startDate và endDate. Tôi đã tryed với let sample = HKQuantitySample(type: type, quantity: quantity, startDate: date, endDate: date, metadata: metadata)
nơi siêu dữ liệu là let metadata = [HKMetadataKeyExternalUUID:"\(Int64(date.timeIntervalSince1970))"]
, nhưng cũng không thành công ...