Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions RCTAppleHealthKit/RCTAppleHealthKit+Methods_Workout.m
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,17 @@ - (void)workout_save: (NSDictionary *)input callback: (RCTResponseSenderBlock)ca
NSTimeInterval duration = [RCTAppleHealthKit doubleFromOptions:input key:@"duration" withDefault:(NSTimeInterval)0];
HKQuantity *totalEnergyBurned = [RCTAppleHealthKit hkQuantityFromOptions:input valueKey:@"energyBurned" unitKey:@"energyBurnedUnit"];
HKQuantity *totalDistance = [RCTAppleHealthKit hkQuantityFromOptions:input valueKey:@"distance" unitKey:@"distanceUnit"];

NSString *workoutBrandName = [RCTAppleHealthKit stringFromOptions:input key:@"workoutBrandName" withDefault:nil];

NSDictionary *metadata = nil;
if (workoutBrandName) {
metadata = @{
HKMetadataKeyWorkoutBrandName: workoutBrandName
};
}

HKWorkout *workout = [
HKWorkout workoutWithActivityType:type startDate:startDate endDate:endDate workoutEvents:nil totalEnergyBurned:totalEnergyBurned totalDistance:totalDistance metadata: nil
HKWorkout workoutWithActivityType:type startDate:startDate endDate:endDate workoutEvents:nil totalEnergyBurned:totalEnergyBurned totalDistance:totalDistance metadata: metadata
];

void (^completion)(BOOL success, NSError *error);
Expand Down
3 changes: 2 additions & 1 deletion docs/saveWorkout.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ let options = {
energyBurned: 50, // In Energy burned unit,
energyBurnedUnit: 'calorie',
distance: 50, // In Distance unit
distanceUnit: 'meter'
distanceUnit: 'meter',
workoutBrandName: "Afternoon Workout"
}
```

Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ declare module 'react-native-health' {
export interface HealthActivityOptions
extends Omit<Omit<HealthValueOptions, 'unit'>, 'value'> {
type: HealthActivity
workoutBrandName?: string
}

export interface HealthObserverOptions {
Expand Down