Creating a HKWorkout of type HKWorkoutActivityType.paddleSports does not allow sharing distance or other HKQuantity types

Originator:bbuck911
Number:rdar://36661069 Date Originated:1/19/18
Status:Open Resolved:No
Product:watchOS + SDK HealthKit Product Version:4.2
Classification:Change Request / Bug Reproducible:Yes
 
Area:
HealthKit

I am developing a workout app specifically for paddle sports, namely kayaking and crew rowing, and have come across an issue while saving the HKWorkout using the HealthKit SDK on watchOS.

The issue is assigning totalDistance to the HKWorkout both using the convenience initializer (illustrated below) or after workout is successfully saved and calling the HKHealthStore func add([HKSample], to: HKWorkout, completion: (Bool, Error?) -> Void) function.

Code snippet:
            let workoutDistance = HKQuantity(unit: HKUnit.meter(), doubleValue: routeManager.routingData.distance.value)
            let energyBurned = HKQuantity(unit: HKUnit.kilocalorie(), doubleValue: 250.0) // TODO: ?? calculated value?
            let metadata = [HKMetadataKeyIndoorWorkout : false]
            // TODO: need workout events - pause etc.
            // save session
            let paddleWorkout = HKWorkout(activityType: .paddleSports,
                                          start: workoutSession.startDate!,
                                          end: workoutSession.endDate!,
                                          workoutEvents: nil,
                                          totalEnergyBurned: energyBurned,
                                          totalDistance: workoutDistance,
                                          metadata: metadata)
            self.healthStore.save(paddleWorkout) { (success, error) -> Void in
                guard success else {
                    if let sessionSaveError = error {
                        debugPrint("*** An error occurred while saving the workout: \(sessionSaveError.localizedDescription)")
                    }
                    return
                }
}

By simply changing ".paddleSport" to ".running" in the HKWorkout instantiation both distance and pace are available in iOS Activity app under Workouts. If paddle sport, no distance/pace is available. HK access permissions are correct so it is not a issue there.

Here is the HK authorization code that gets called earlier in the app lifecycle:
let shareTypes: Set<HKSampleType> = [HKWorkoutType.workoutType(),
                                                 HKSeriesType.workoutRoute(),
                                                 HKObjectType.quantityType(forIdentifier: .distanceWalkingRunning)!]
            healthKitStore.requestAuthorization(toShare: shareTypes, read: sampleTypes, completion: { (success, error) in
...
}

Notice in the shareTypes I had to use ".distanceWalkingRunning" since there is no option for distance for paddle sports.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!