Skip to main content
The iOS SDK is coming soon. This documentation is a preview.

Swift Package Manager

The Whop iOS SDK is distributed via Swift Package Manager. This is the recommended way to install the SDK.

Step 1: Add Package Dependency

In Xcode, go to FileAdd Package Dependencies… Enter the package URL:
https://github.com/whopio/whopsdk-chat-swift

Step 2: Select Version

Choose the latest version or specify a version range:
  • Up to Next Major: Recommended for production
  • Exact Version: For stability
  • Branch: For development

Step 3: Import the SDK

Import Whop in your Swift files:
import WhopChat

Configuration

Initialize the SDK with a token provider that fetches authentication tokens from your backend:
import SwiftUI
import Whop

@main
struct YourApp: App {
    init() {
        Whop.configure(
            appID: "app_xxxxxxxxxxxxxx",
            tokenProvider: {
                try await fetchWhopToken()
            }
        )
    }

    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }

    func fetchWhopToken() async throws -> String {
        let url = URL(string: "https://your-api.com/whop/token")!
        let (data, _) = try await URLSession.shared.data(from: url)
        let response = try JSONDecoder().decode(TokenResponse.self, from: data)
        return response.token
    }
}

struct TokenResponse: Codable {
    let token: String
}

Backend Setup

Your backend needs to provide an endpoint that returns Whop tokens for authenticated users.

Example: Next.js API Route

import { NextRequest } from "next/server";
import Whop from "@whop/sdk";

const whop = new Whop({
  appID: process.env.WHOP_APP_ID!,
  apiKey: process.env.WHOP_API_KEY!,
});

export async function GET(request: NextRequest) {
  const session = await getYourAppSession(request);

  if (!session?.userId) {
    return Response.json({ error: "Unauthorized" }, { status: 401 });
  }

  const token = await whop.accessTokens.create({
    user_id: mapToWhopUserId(session.userId),
  });

  return Response.json({ token: token.access_token });
}

How it works

  1. Your iOS app calls the tokenProvider closure
  2. The closure makes a request to your backend
  3. Your backend verifies the user’s session
  4. Your backend creates a Whop access token for that user
  5. The token is returned to the SDK
  6. The SDK uses this token for all chat operations
The tokenProvider is called automatically when:
  • The SDK first initializes
  • A token expires and needs refresh
  • A network request fails with 401

Next Steps

Embedded Chat

Start building with embedded chat