Open Mravuri96 opened 1 year ago
@kvs-coder I was able to fix this in this repo. But since Workout.make
always overwrites the uuid, the quantities can never be added to an already existing workout. I am also assuming addCategory
is also broken.
Fix
private func addQuantity(
reporter: HealthKitReporter,
arguments: [String: Any],
result: @escaping FlutterResult
) {
guard
let quantity = arguments["quantities"] as? [[String: Any]],
let workout = arguments["workout"] as? [String: Any]
else {
throwParsingArgumentsError(result: result, arguments: arguments)
return
}
let device = arguments["device"] as? [String: Any]
do {
let w = try Workout.make(from: workout)
reporter.writer.addQuantitiy(
try quantity.map {
let q = try Quantity.make(from: $0)
return q.copyWith(
startTimestamp: q.startTimestamp.secondsSince1970,
endTimestamp: q.endTimestamp.secondsSince1970
)
},
from: device != nil
? try Device.make(from: device!)
: nil,
to: w.copyWith(
startTimestamp: w.startTimestamp.secondsSince1970,
endTimestamp: w.endTimestamp.secondsSince1970,
workoutEvents: w.workoutEvents.map { event in
event.copyWith(
startTimestamp: event.startTimestamp.secondsSince1970,
endTimestamp: event.endTimestamp.secondsSince1970
)
}
)
) { (success, error) in
guard error == nil else {
result(
FlutterError(
code: "AddQuantity",
message: "Error in addQuantity",
details: error.debugDescription
)
)
return
}
result(success)
}
} catch {
throwPlatformError(result: result, error: error)
}
}
Describe the bug Using the
await HealthKitReporter.addQuantity
function causes the app to hard crash.To Reproduce
Error
Swift Equivalent