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

# Triggering Delegation

> How to trigger delegation for a user in Swift.

In your application, when a user is logged in, you'll want to request delegation for your application.

<Info>
  Make sure you have [configured delegated access](/overview/wallets/embedded-wallets/mpc/delegated-access/configuration) in the dashboard before triggering delegation.
</Info>

## Dynamic's UI

### Auto-prompt User on Sign In

If you chose to prompt the user on sign in during the [configuration step](/overview/wallets/embedded-wallets/mpc/delegated-access/configuration), the user is prompted to approve delegation for your application when they next sign in.

### Trigger Delegation Manually

You can use the `initDelegationProcess` method from the wallets module to open the delegation modal UI:

```swift theme={"system"}
// Open the delegation modal for all eligible wallets
try await DynamicSDK.instance.wallets.initDelegationProcess()

// Or specify which wallets to delegate
try await DynamicSDK.instance.wallets.initDelegationProcess(
    walletIds: ["wallet-id-1", "wallet-id-2"]
)
```

### Check If User Should Be Prompted

Before prompting, you can check whether the user should see a delegation prompt:

```swift theme={"system"}
let shouldPrompt = try await DynamicSDK.instance.wallets.shouldPromptWalletDelegation()

if shouldPrompt {
    try await DynamicSDK.instance.wallets.initDelegationProcess()
}
```

## Your Own UI

You can use `delegateKeyShares` to delegate wallets programmatically without showing any Dynamic UI:

```swift theme={"system"}
// Delegate all eligible wallets
try await DynamicSDK.instance.wallets.delegateKeyShares()

// Or delegate specific wallets
try await DynamicSDK.instance.wallets.delegateKeyShares(
    wallets: [
        DelegationWalletIdentifier(
            chainName: .evm,
            accountAddress: "0x123..."
        ),
        DelegationWalletIdentifier(
            chainName: .sol,
            accountAddress: "ABC123..."
        )
    ]
)
```

## Monitor Delegation State

You can observe delegation state changes using Combine:

```swift theme={"system"}
import Combine

// Get current state synchronously
let state = DynamicSDK.instance.wallets.delegatedAccessState
print("Enabled: \(state.delegatedAccessEnabled ?? false)")
print("Required: \(state.requiresDelegation ?? false)")

// Listen to state changes
var cancellables = Set<AnyCancellable>()

DynamicSDK.instance.wallets.delegatedAccessChanges
    .sink { state in
        for wallet in state.walletsDelegatedStatus {
            print("\(wallet.address): \(wallet.status)")
        }
    }
    .store(in: &cancellables)
```

## Check Wallet Delegation Status

```swift theme={"system"}
// Get status of all wallets
let statuses = try await DynamicSDK.instance.wallets.getWalletsDelegatedStatus()

for status in statuses {
    print("Wallet \(status.address) on \(status.chain): \(status.status)")
}

// Get status for a specific wallet
if let status = DynamicSDK.instance.wallets.getDelegationStatusForWallet("wallet-id") {
    print("Status: \(status.status)") // .delegated, .pending, or .denied
}
```

## Dismiss or Deny Delegation

```swift theme={"system"}
// Dismiss the prompt for the current session only (resets on logout/restart)
try await DynamicSDK.instance.wallets.dismissDelegationPrompt()

// Or dismiss for a specific wallet
try await DynamicSDK.instance.wallets.dismissDelegationPrompt(walletId: "wallet-id")

// Permanently deny delegation for a wallet (user won't be prompted again)
try await DynamicSDK.instance.wallets.denyWalletDelegation(walletId: "wallet-id")

// Clear all session dismissals
try await DynamicSDK.instance.wallets.clearDelegationSessionState()
```

<Card title="What's next?" icon="link" color="#4779FE" href="/swift/wallets/embedded-wallets/mpc/delegated-access/receiving-delegation">
  Learn how to properly receive the delegation materials on your server
</Card>
