<!--
{
  "availability" : [
    "iOS: 17.0.0 -",
    "iPadOS: 17.0.0 -",
    "macCatalyst: 17.0.0 -",
    "macOS: -",
    "visionOS: 1.0.0 -",
    "watchOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "HealthKit",
  "identifier" : "/documentation/HealthKit/HKWorkoutSessionDelegate/workoutSession(_:didDisconnectFromRemoteDeviceWithError:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "HealthKit"
    ],
    "preciseIdentifier" : "c:objc(pl)HKWorkoutSessionDelegate(im)workoutSession:didDisconnectFromRemoteDeviceWithError:"
  },
  "title" : "workoutSession(_:didDisconnectFromRemoteDeviceWithError:)"
}
-->

# workoutSession(_:didDisconnectFromRemoteDeviceWithError:)

Tells the delegate that the mirrored workout session disconnected from the primary session.

```
optional func workoutSession(_ workoutSession: HKWorkoutSession, didDisconnectFromRemoteDeviceWithError error: (any Error)?)
```

## Parameters

`workoutSession`

The mirrored workout session that disconnected.

`error`

If an error caused the disconnection, then this parameter contains the error value. Otherwise, it’s `nil`.

## Discussion

After the system calls this method, the provided workout session is no longer valid, and you can no longer use it.

```swift
func clearWorkoutSession() {
    state = .notRunning
    session = nil
}

nonisolated func workoutSession(_ workoutSession: HKWorkoutSession, didDisconnectFromRemoteDeviceWithError error: Error?) {
    Task {
        // Clear the old session.
        await clearWorkoutSession()
    }

    logger.debug("*** Remote workout session disconnected. ***")
    if let error {
        fatalError("*** Disconnected with an error: \(error.localizedDescription) ***")
    }
}
```

If the primary workout session is still running, it automatically tries to reconnect. If successful, the companion iOS device calls the [`workoutSessionMirroringStartHandler`](/documentation/HealthKit/HKHealthStore/workoutSessionMirroringStartHandler) block again, passing in a new, valid [`HKWorkoutSession`](/documentation/HealthKit/HKWorkoutSession) instance.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)