I add sample like this:
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!")
}
})
And when I want to delete this sample I execute:
store.deleteObject(sample, withCompletion: {(success, error) -> Void in
if(error != nil) {
println("Error deleting sample: \(error.localizedDescription)")
}else{
println("Sample deleted successfully!")
}
})
And it returns me: Error deleting sample: object not found
Everytime I use the same 'date' for startDate and endDate.
I've tryed with let sample = HKQuantitySample(type: type, quantity: quantity, startDate: date, endDate: date, metadata: metadata)
where metadata is let metadata = [HKMetadataKeyExternalUUID:"\(Int64(date.timeIntervalSince1970))"]
, but also unsuccessfully...
It is not possible to delete the Health data which is entered by ApplicationA in ApplicationB, other than Apple's Health app.
As per Apple's documentation, it is possible to delete the health data which is created by the respective application only. Though, user given write permission, it is not possible to delete some other applications health data from your application, but it is possible from Apple's Health application only.
From the documentation:
NOTE
Although your app can manage only the objects it created and saved, the users can delete any data they want using the Health app.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With