<!--
{
  "availability" : [
    "iOS: 12.5.0 - 27.0.0",
    "iPadOS: 12.5.0 - 27.0.0",
    "macCatalyst: 12.5.0 - 27.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "ExposureNotification",
  "identifier" : "/documentation/ExposureNotification/ENManager/getDiagnosisKeys(completionHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Exposure Notification"
    ],
    "preciseIdentifier" : "c:objc(cs)ENManager(im)getDiagnosisKeysWithCompletionHandler:"
  },
  "title" : "getDiagnosisKeys(completionHandler:)"
}
-->

# getDiagnosisKeys(completionHandler:)

Requests the temporary exposure keys from the user’s device to share with a server.

```
func getDiagnosisKeys(completionHandler: @escaping @Sendable ([ENTemporaryExposureKey]?, (any Error)?) -> Void)
```

## Parameters

`completionHandler`

The completion handler that the framework calls when [`getDiagnosisKeys(completionHandler:)`](/documentation/ExposureNotification/ENManager/getDiagnosisKeys(completionHandler:)) completes. If the method completes successfully, `keys` will contain the diagnosis keys for this device and `error` will be `nil`. If it fails, `keys` will be `nil` and `error` indicates the reason it failed.

## Discussion

> Important:
> You can call this method from synchronous code using a completion handler, as shown on this page, or you can call it as an asynchronous method that has the following declaration:
> 
> ```swift
> func diagnosisKeys() async throws -> [ENTemporaryExposureKey]
> ```
> 
> For information about concurrency and asynchronous code in Swift, see <doc://com.apple.documentation/documentation/Swift/calling-objective-c-apis-asynchronously>.

> Important:
> This method is available in iOS 12.5, and in iOS 13.5 and later.

The app must be in the foreground when it calls this method. Each time the app calls this method, the system presents an interface that requests authorization.

When <doc://com.apple.documentation/documentation/BundleResources/Information-Property-List/ENAPIVersion> is set to `1` in the app’s Info.plist file, you must wait approximately 24 hours after the first call of [`getDiagnosisKeys(completionHandler:)`](/documentation/ExposureNotification/ENManager/getDiagnosisKeys(completionHandler:)) before this call returns a valid key. To test your app without waiting 24 hours, use [`getTestDiagnosisKeys(completionHandler:)`](/documentation/ExposureNotification/ENManager/getTestDiagnosisKeys(completionHandler:)).

When <doc://com.apple.documentation/documentation/BundleResources/Information-Property-List/ENAPIVersion> is set to `2`, this call returns a diagnosis key with a shortened rolling period.

## Topics

### Completion Handlers

[`ENGetDiagnosisKeysHandler`](/documentation/ExposureNotification/ENGetDiagnosisKeysHandler)

The definition of a handler that returns diagnosis keys.



---

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)