How to delete Exercise minutes data from the activity ring?

I have followed the below function to delete the HKWorkout object, It is deleting Active Energy and Distance data but it is NOT deleting Excercise minute data, so the activity ring always displays Excercise minutes data even after deleting a particular workout entry.

let predicate = HKQuery.predicateForSamples(withStart: workout.start, end: workout.end, options: .strictStartDate)
let findQuery = HKSampleQuery(sampleType: deletedType, predicate: predicate, limit: 1, sortDescriptors: nil) {
        query, results, error in
        if results != nil {
            print("\nHere we got not nil on results!\n")
            for result in (results as? [HKWorkout])! {
                
                self.healthStore.delete(result) { [unowned self] (status, error) in
                    if status == true {

                        print("Successfully deleted HKWorkout.")

                    } else {
                        print("Error \(String(describing: error?.localizedDescription))")
                    }
                }
            }
        } else {
            print("results are nil")
            return
        }
    }
    self.healthStore.execute(findQuery)


Replies

Exercise minutes for workouts saved on phone are awarded by the system and you cannot delete those. The user has to manually delete them in the Health app.

  • Thank you very much for your prompt response!!!

Add a Comment