Add custom metadata to HKLiveWorkoutBuilder

I'm trying to sync workouts for which I have to add the HKMetadataKeySyncIdentifier and HKMetadataKeySyncVersion metadata keys to the workouts.

I've tried calling the addMetadata method on HKLiveWorkoutBuilder but I receive this cryptic error:
Code Block
HKLiveWorkoutBuilder_DB2D [E6B9]: (#w0) Failed to restart task server after connection invalidation: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service on pid 0 created from an endpoint was invalidated from this process." UserInfo={NSDebugDescription=The connection to service on pid 0 created from an endpoint was invalidated from this process.}

Here's my code:
Code Block Swift
backend = try! HKWorkoutSession(healthStore: healthStore, configuration: workoutConfiguration)
builder = session?.associatedWorkoutBuilder()
let metadata : NSDictionary = [
HKMetadataKeySyncIdentifier : match.syncIdentifier,
HKMetadataKeySyncVersion: match.syncVersion
]
builder.addMetadata(metadata as! [String : Any]) { (success, error) in
...
}
session.delegate = self
builder.delegate = self
...


Accepted Reply

Okay I've solved it: Its important to convert the string to an NSString. The dictionary would become this:
Code Block Swift
let metadata : NSDictionary = [
HKMetadataKeySyncIdentifier : NSString(string: match.syncIdentifier.uuidString),
HKMetadataKeySyncVersion: match.syncVersion
]

I'm leaving it up here in case somebody else comes across the same problem
  • Can you spare a note on HOW you found the solution? I have the same exact error, but in totally different scenario - anonymous XPC service listener I create programmatically, suddenly goes astray with this error --- and I can't figure why. Now I got the idea that some remote call had wrong parameter values, or was null where null is forbidden, or something of that sort - and I'll review - but maybe you got more information to help you solve the issue?

Add a Comment

Replies

Okay I've solved it: Its important to convert the string to an NSString. The dictionary would become this:
Code Block Swift
let metadata : NSDictionary = [
HKMetadataKeySyncIdentifier : NSString(string: match.syncIdentifier.uuidString),
HKMetadataKeySyncVersion: match.syncVersion
]

I'm leaving it up here in case somebody else comes across the same problem
  • Can you spare a note on HOW you found the solution? I have the same exact error, but in totally different scenario - anonymous XPC service listener I create programmatically, suddenly goes astray with this error --- and I can't figure why. Now I got the idea that some remote call had wrong parameter values, or was null where null is forbidden, or something of that sort - and I'll review - but maybe you got more information to help you solve the issue?

Add a Comment