Puzzling error inserting data into HKWorkoutRouteBuilder in watchOS 4 Beta 4

943 Views Asked by At

When I insert route data into HKWorkoutRouteBuilder I get the following error:

The connection to service named com.apple.healthd.server was interrupted, but the message was sent over an additional proxy and therefore this proxy has become invalid

Here's a code snippet.

    workoutRouteBuilder.insertRouteData(filteredLocations) { (success, error) in
        if !success {
            print("inserting route data failed with error: \(String(describing: error))")
        }
    }

I patterned by impelementation from the Speed Sloth example.

Any insights would be appreciated!

UPDATE: Here's some more info from the watch logs. Looks like some sort of permission issue, but I haven't been able to track it down yet:

fault 13:21:14.664262 -0400 healthd connection from pid 1705: Warning: Exception caught during invocation of received message, dropping incoming message and invalidating the connection. Exception: Invalid parameter not satisfying: [authorizationStatuses count] == [typesIncludingParentTypes count] Invalid parameter not satisfying: [authorizationStatuses count] == [typesIncludingParentTypes count] ( 0 CoreFoundation
0x1dc04d25 + 153 1 libobjc.A.dylib
0x1d227181 objc_exception_throw + 39 2 CoreFoundation
0x1dc04be5 + 1 3 Foundation
0x1e43c1cd + 93 4 HealthDaemon
0x2edf678f + 2015 5 HealthDaemon
0x2ee6eed1 + 143 6 HealthDaemon
0x2ee6ec77 + 143 7 HealthDaemon
0x2ee7b99b + 485 8 HealthDaemon
0x2f0e1e1f + 143 9 Foundation
0x1e589393 + 19 10 Foundation
0x1e587<…>

3

There are 3 best solutions below

3
On BEST ANSWER

I had the same problem. You need to ensure that you request authorisation from the user for:

// Objective C
[HKSeriesType workoutRouteType]

// Swift
HKSeriesType.workoutRoute()
0
On

Don’t forget to add request of WorkoutRoute for HKHealthStore at AppDelegate

Workout Route does not work with Simulator, and only works with some HKWorkoutActivityType like .walking, .running on OS4

private func requestAccessToHealthKit() {

    let healthStore = HKHealthStore()

    let allTypes = Set([HKObjectType.workoutType(),
                        HKObjectType.quantityType(forIdentifier: .activeEnergyBurned)!,
                        HKObjectType.quantityType(forIdentifier: .distanceWalkingRunning)!])
    if #available(watchOS 4.0, *) {
        allTypes.insert(HKSeriesType.workoutRoute())
    }
    healthStore.requestAuthorization(toShare: allTypes, read: allTypes) { (success, error) in
        if !success {
            print(error?.localizedDescription ?? "")
        }
    }
}
1
On

The connection to service named com.apple.healthd.server was interrupted, but the message was sent over an additional proxy and therefore this proxy has become invalid

Seeing this message indicates that the system process handling the request has crashed or exited. You should file a bug with Apple. Look for healthd crash logs and include them.