قالب وردپرس درنا توس
Home / IOS Development / ios – HealthKit Error "Could not Find Any Objects for Deletion" When You Try to Delete HKWorkout

ios – HealthKit Error "Could not Find Any Objects for Deletion" When You Try to Delete HKWorkout



I have had a long-standing problem with receiving this error from HealthKit when I try to "modify" a HKWorkout by (1) copying an existing workout session (2) updating the metadata (3) "old" workout (selectWorkout in my code below) then (4) stores the new modified training. 98% of the time this code works flawlessly, but 2% of the time I will get this error and I will end up with duplicate workouts. Am I doing something wrong?

As a page, I wish that HealthKit would let us change data so that this dance was not necessary.

  class func updateMetadataDeleteOldAndSaveNewWorkout (selectedWorkout: HKWorkout, trades: @escaping (Bool, WorkoutManagerError?) -> Feid) {

// configure metadata

// Create a new training with the fields in the old workout and the new edited metadata object
la newWorkout = HKWorkout (activityType: selectedWorkout.workoutActivityType, start: selectedWorkout.startDate, end: selectWorkout.endDate, duration: selectedWorkout.duration, totalEnergyBurned: selectedWorkout.totalEnergyBurned, totalDistance: selectedWorkout.totalDistance, metadata: metadata)

// Delete the old exercise
HealthStoreSingleton.sharedInstance.healthStore.delete (selectedWorkout, withCompletion: {(success, error) in

DispatchQueue.main.async {

if la unwrappedError = error {
trades (false, WorkoutManagerError.deleteError (unwrappedError.localizedDescription))
return
}
}

// When the deletion was successful, save the new training
HealthStoreSingleton.sharedInstance.healthStore.save (newWorkout) {success, error in

DispatchQueue.main.async {
if la unwrappedError = error {
Trades (False, WorkoutManagerError.saveError (unwrappedError.localizedDescription))
return
}

whose success {

trades (true, zero)
return
} other {
trades (false, WorkoutManagerError.saveError (" (String (describes: error))"))
return
}
}
}
})


Source link