Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete added sample in Health App

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...

like image 255
Bogdan Bogdanov Avatar asked Jan 30 '15 15:01

Bogdan Bogdanov


1 Answers

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.

like image 158
Bhanu Prakash Avatar answered Nov 09 '22 08:11

Bhanu Prakash