Install the SDK

Configure Environment Variables

The SDK needs to know which Dynamic environment to connect to. You’ll need to set up environment variables in your Xcode scheme:
  1. In Xcode, go to Product → Scheme → Edit Scheme
  2. Select “Run” from the left sidebar
  3. Go to the “Arguments” tab
  4. Under “Environment Variables”, add the following:
DYNAMIC_BASE_URL = https://app.dynamicauth.com/api/v0
DYNAMIC_RELAY_HOST = relay.dynamicauth.com
DYNAMIC_ENVIRONMENT_ID = <your_environment_id>
Replace <your_environment_id> with the environment ID from your Dynamic dashboard.

Configure URL Scheme

Add a URL scheme to your Info.plist for social authentication callbacks:
Info.plist
<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLName</key>
        <string>com.yourcompany.yourapp</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>yourapp</string>
        </array>
    </dict>
</array>

Initialize the SDK

Complete Initialization Example

Here’s a complete example showing how to initialize the SDK with session state management and Ethereum connector:
import DynamicSwiftSDK
import SwiftUI

struct ContentView: View {
    @State private var client: DynamicClient?
    @StateObject private var sessionState = DynamicSessionState()

    var body: some View {
        // Your app content here
        Text("Dynamic Swift Demo")
    }

    private func initialize() async {
        let config = DynamicClientConfig(
            environmentId: ProcessInfo.processInfo.environment["DYNAMIC_ENVIRONMENT_ID"] ?? "your-env-id"
        )

        let newClient = createDynamicClient(config: config)
        client = newClient

        // Bind session state for automatic UI updates
        bindSessionState(sessionState, to: newClient)

        // Add Ethereum connector for blockchain functionality
        do {
            try await addEthereumConnector(
                to: newClient,
                networkConfigProvider: GenericNetworkConfigurationProvider(),
                initialChainId: 84532  // Base Testnet
            )
        } catch {
            print("Failed to add Ethereum connector: \(error)")
        }
    }

    private func refreshSettingsIfNeeded() async {
        guard let existingClient = client else { return }
        do {
            try await initializeClient(client: existingClient)
        } catch {
            print("Failed to refresh client settings: \(error)")
        }
    }
}

Enable Features in Dashboard

Before you can use authentication and wallet features, you need to enable them in your Dynamic dashboard:
  1. Go to your Dynamic Dashboard
  2. Select your project
  3. Go to Authentication and enable the methods you want to use:
    • Email OTP
    • SMS OTP
    • Social providers (Apple, Google, etc.)
  4. Go to Wallets and enable embedded wallets
  5. Go to Chains and enable the networks you want to support
For testing, we recommend starting with Email OTP authentication and Ethereum Sepolia testnet. This gives you a complete setup without requiring real phone numbers or mainnet transactions.

Troubleshooting

Common Issues

  • Could not find module ‘DynamicSwiftSDK’
    • Make sure you’ve added the package to your target
    • Try cleaning the build folder (Product → Clean Build Folder)
    • Restart Xcode
  • Environment ID not found
    • Check that you’ve set the DYNAMIC_ENVIRONMENT_ID environment variable
    • Verify the environment ID in your Dynamic dashboard
    • Make sure you’re using the correct environment (sandbox vs live)
  • Network connection failed
    • Check your internet connection
    • Verify the DYNAMIC_BASE_URL and DYNAMIC_RELAY_HOST environment variables
    • Ensure your environment is active in the Dynamic dashboard
  • Session state not updating
    • Make sure you’re calling bindSessionState(sessionState, to: client) after creating the client
    • Verify that your UI is observing the DynamicSessionState object

What’s Next

Great! Your SDK is now configured and ready to use. Here’s what you can do next:
  1. Authentication Guide - Learn how to implement user authentication with email and SMS OTP
  2. Social Authentication - Add social login options like Apple and Google
  3. Wallet Creation - Create and manage embedded wallets for your users
  4. Networks - Configure blockchain networks
📱 Complete Example App: For a fully functional iOS app demonstrating all SDK features, check out our Swift Example Repository. It includes authentication flows, wallet management, and Ethereum transaction examples with SwiftUI.