> ## Documentation Index
> Fetch the complete documentation index at: https://docs.polygon.technology/llms.txt
> Use this file to discover all available pages before exploring further.

# Swift Manage Sessions

> Restore sessions, manage access, and sign out with the Swift OMS Wallet SDK.

Use the Swift SDK session APIs after authentication to restore wallet state, issue ID tokens, and manage credential access.

## Session Restore

The SDK stores wallet metadata and the request-signing credential in the device keychain. A saved completed session is restored automatically when `OMSClient` is created.

```swift theme={null}
let oms = try OMSClient(publishableKey: "YOUR_PUBLISHABLE_KEY")

if let walletAddress = oms.wallet.session.walletAddress {
    print("Restored wallet:", walletAddress)
}
```

**Returns**

`oms.wallet.session` returns `SessionState` with `walletAddress`, `expiresAt`, `loginType`, and `sessionEmail`.

## Session Expiry Events

Assign `onSessionExpired` when the app should react as soon as the active wallet session expires.

```swift theme={null}
oms.wallet.onSessionExpired = { event in
    print("Session expired at:", event.expiredAt)
    print("Expired wallet:", event.session.walletAddress ?? "")
}
```

Keep the handler assigned while the owner needs updates. Assign `nil` during cleanup.

**Parameters**

| Parameter          | Type                               | Description                                                                               |
| ------------------ | ---------------------------------- | ----------------------------------------------------------------------------------------- |
| `onSessionExpired` | `((SessionExpiredEvent) -> Void)?` | Optional handler that receives `session` and `expiredAt` when the wallet session expires. |

**Returns**

The handler returns `Void`.

## List Wallets

List wallets available to the authenticated credential.

```swift theme={null}
let wallets = try await oms.wallet.listWallets()

for wallet in wallets {
    print(wallet.id, wallet.type, wallet.address)
}
```

**Parameters**

Takes no parameters.

**Returns**

Returns `[Wallet]`.

## Get ID Token

Request an ID token for the active wallet session. Send this token to your backend when using [backend wallet verification](/wallets/sdk/guides/backend-wallet-verification).

```swift theme={null}
let idToken = try await oms.wallet.getIdToken(ttlSeconds: 300)
```

**Parameters**

| Parameter      | Type                         | Description                                                                                                         |
| -------------- | ---------------------------- | ------------------------------------------------------------------------------------------------------------------- |
| `ttlSeconds`   | `UInt32?`                    | Optional token lifetime in seconds.                                                                                 |
| `customClaims` | `[String: WebRPCJSONValue]?` | Optional app-provided claims. Backends should treat them as client-provided context unless they control the values. |

**Returns**

Returns `String`.

## List Access

List wallet access grants for account-management UI.

```swift theme={null}
let credentials = try await oms.wallet.listAccess()

for credential in credentials {
    print(credential.credentialId, credential.expiresAt, credential.isCaller)
}
```

**Parameters**

| Parameter  | Type      | Description                                                              |
| ---------- | --------- | ------------------------------------------------------------------------ |
| `pageSize` | `UInt32?` | Optional page size for each access-list request while loading all pages. |

**Returns**

Returns `[CredentialInfo]`.

## List Access Pages

Use `listAccessPages` when your UI should render credential access one page at a time.

```swift theme={null}
for try await page in oms.wallet.listAccessPages(pageSize: 25) {
    for credential in page.credentials {
        print(credential.credentialId, credential.isCaller)
    }
}
```

**Parameters**

| Parameter  | Type      | Description                                      |
| ---------- | --------- | ------------------------------------------------ |
| `pageSize` | `UInt32?` | Optional page size for each access-list request. |

**Returns**

Returns `ListAccessPages`, an async sequence of `ListAccessResponse` values.

## List Access Page

Fetch one credential-access page with an optional cursor.

```swift theme={null}
let page = try await oms.wallet.listAccessPage(pageSize: 25)
let nextCursor = page.page?.cursor
```

**Parameters**

| Parameter  | Type      | Description                                  |
| ---------- | --------- | -------------------------------------------- |
| `pageSize` | `UInt32?` | Optional page size for this request.         |
| `cursor`   | `String?` | Optional cursor returned by a previous page. |

**Returns**

Returns `ListAccessResponse`.

## Revoke Access

Revoke another credential's access to the active wallet.

```swift theme={null}
try await oms.wallet.revokeAccess(targetCredentialId: "credential-id")
```

**Parameters**

| Parameter            | Type     | Description                               |
| -------------------- | -------- | ----------------------------------------- |
| `targetCredentialId` | `String` | Credential ID returned by `listAccess()`. |

**Returns**

Returns `Void`.

## Sign Out

```swift theme={null}
try oms.wallet.signOut()
```

Signing out clears the saved wallet session and authentication state from the keychain. The user must authenticate again before wallet operations.

**Parameters**

Takes no parameters.

**Returns**

Returns `Void`.
