### Install WhopElements via Swift Package Manager
Source: https://github.com/whopio/whopsdk-elements-swift/blob/main/README.md
Add the SDK dependency to your Package.swift file with the specified version.
```swift
dependencies: [
.package(url: "https://github.com/whopio/whopsdk-elements-swift.git", exact: "0.0.21")
]
```
--------------------------------
### Configure OAuth Authentication
Source: https://github.com/whopio/whopsdk-elements-swift/blob/main/README.md
Methods for initializing the SDK, checking authentication status, and performing manual sign-in or sign-out.
```swift
// At app launch
await WhopSDK.configureWithOAuth(appId: "app_XXXXXXXXXXXXXX")
// Check authentication state
if WhopSDK.isAuthenticated {
// User is logged in
}
// Manual sign in (optional - all chat components will open the OAuth flow if not authenticated)
try await WhopSDK.signIn()
// Sign out
WhopSDK.signOut()
```
--------------------------------
### Configure Info.plist Permissions
Source: https://github.com/whopio/whopsdk-elements-swift/blob/main/README.md
Include these usage descriptions in your Info.plist to support KYC and media features within the SDK.
```xml
NSCameraUsageDescription
We use your camera to let you take photos, record videos, and ID verification.
NSMicrophoneUsageDescription
We use your microphone so you can record and share audio, and ID verification.
NSPhotoLibraryUsageDescription
We use your photo library so you can select and share photos or videos from your library.
```
--------------------------------
### WhopSDK.configureWithOAuth
Source: https://github.com/whopio/whopsdk-elements-swift/blob/main/README.md
Initializes the Whop SDK with the provided application ID. This must be called as early as possible in the application lifecycle.
```APIDOC
## WhopSDK.configureWithOAuth
### Description
Configures the SDK for OAuth authentication.
### Parameters
- **appId** (String) - Required - The application ID registered in the Whop developer dashboard.
```
--------------------------------
### Implement WhopPayoutsView in SwiftUI
Source: https://github.com/whopio/whopsdk-elements-swift/blob/main/README.md
Defines a token provider to fetch access tokens and initializes the WhopPayoutsView within a SwiftUI view hierarchy.
```swift
import SwiftUI
import WhopElements
class PayoutsTokenProvider: WhopTokenProvider {
/// For Payouts and Checkout, you can use a token linked to your company.
/// Fetch it in your backend using https://docs.whop.com/api-reference/access-tokens/create-access-token
func getToken() async -> WhopTokenResponse {
let token = await fetchAccessToken()
return WhopTokenResponse(accessToken: token)
}
}
struct WhopPayoutsExample: View {
var body: some View {
WhopPayoutsView(
thirdPartyClient: "My Company Name",
companyId: "biz_xxxxxxxx",
ledgerAccountId: "ldgr_xxxxxxxx"
)
.task {
// Ideally initialize as early as possible so views don't wait
await WhopSDK.configure(tokenProvider: PayoutsTokenProvider())
}
}
}
```
--------------------------------
### Implement WhopDMsListView
Source: https://github.com/whopio/whopsdk-elements-swift/blob/main/README.md
Displays a list of direct message conversations and handles channel selection navigation.
```swift
import SwiftUI
import WhopElements
struct WhopDMsListExample: View {
@State private var selectedChannel: DMChannel?
var body: some View {
WhopDMsListView { event in
switch event {
case let .channelSelected(channel):
selectedChannel = channel
}
}
.navigationTitle("Messages")
.navigationDestination(item: $selectedChannel) { channel in
WhopChatView(channelId: channel.id, style: .imessage)
.navigationBarTitleDisplayMode(.inline)
.navigationTitle(channel.name)
}
.task {
// Ideally initialize as early as possible so views don't wait
await WhopSDK.configureWithOAuth(appId: "app_XXXXXXXXXXXXXX")
}
}
}
```
--------------------------------
### Implement WhopChatView in SwiftUI
Source: https://github.com/whopio/whopsdk-elements-swift/blob/main/README.md
Integrates the chat interface into a SwiftUI view and handles chat events via the onEvent callback.
```swift
import SwiftUI
import WhopElements
struct WhopChatExample: View {
var body: some View {
WhopChatView(
channelId: "chat_xxxxxxxxxxxxxxxxx",
style: .imessage,
onEvent: { event in
switch event {
case let .profileTap(username, userId):
print("Profile tapped: \(username), userId: \(userId)")
case let .urlTap(url):
print("URL tapped: \(url)")
case let .messageSent(content):
print("Message sent: \(content)")
}
}
)
.task {
// Ideally initialize as early as possible so views don't wait
await WhopSDK.configureWithOAuth(appId: "app_XXXXXXXXXXXXXX")
}
}
}
```
--------------------------------
### WhopPayoutsView
Source: https://github.com/whopio/whopsdk-elements-swift/blob/main/README.md
A SwiftUI view that displays the payouts management interface. It requires configuration via WhopSDK.configure and a token provider.
```APIDOC
## WhopPayoutsView
### Description
Displays the payouts management interface for withdrawals and earnings within a SwiftUI application.
### Parameters
- **thirdPartyClient** (String) - Required - Your company name displayed in the UI.
- **companyId** (String) - Required - Your Whop company ID (biz_xxx).
- **ledgerAccountId** (String) - Required - The ledger account ID (ldgr_xxx).
- **currency** (String) - Optional - Currency code, defaults to "usd".
### Usage Example
```swift
WhopPayoutsView(
thirdPartyClient: "My Company Name",
companyId: "biz_xxxxxxxx",
ledgerAccountId: "ldgr_xxxxxxxx"
)
```
```
--------------------------------
### WhopChatView
Source: https://github.com/whopio/whopsdk-elements-swift/blob/main/README.md
A SwiftUI view component that renders a chat interface. It requires configuration via WhopSDK.configureWithOAuth before use.
```APIDOC
## WhopChatView
### Description
Displays a real-time chat interface with support for different visual styles.
### Parameters
- **channelId** (String) - Required - Chat channel ID (chat_xxx) or DM feed ID (feed_xxx)
- **deeplinkToPostId** (String) - Optional - Post ID to scroll to
- **style** (ChatStyle) - Required - Visual style: .imessage or .discord
- **onEvent** (Closure) - Required - Callback for chat events (profileTap, urlTap, messageSent)
### Usage Example
```swift
WhopChatView(
channelId: "chat_xxxxxxxxxxxxxxxxx",
style: .imessage,
onEvent: { event in
// Handle events
}
)
```
```
--------------------------------
### WhopSDK Authentication
Source: https://github.com/whopio/whopsdk-elements-swift/blob/main/README.md
Methods for configuring, checking, and managing OAuth authentication state within the Whop SDK.
```APIDOC
## WhopSDK Authentication
### Description
Methods to initialize the SDK with OAuth, check the current authentication status, and perform manual sign-in or sign-out operations.
### Methods
- **WhopSDK.configureWithOAuth(appId: String)** - Initializes the SDK with the provided App ID. Should be called at app launch.
- **WhopSDK.isAuthenticated** (Bool) - Returns the current authentication status.
- **WhopSDK.signIn()** - Manually triggers the OAuth sign-in flow.
- **WhopSDK.signOut()** - Signs the user out of the SDK.
### View Modifier
- **.whopAuthState(Binding)** - A view modifier to track the authentication state in a SwiftUI view.
```
--------------------------------
### WhopDMsListView
Source: https://github.com/whopio/whopsdk-elements-swift/blob/main/README.md
A SwiftUI view component that displays a list of direct message conversations. It provides an event handler to manage channel selection.
```APIDOC
## WhopDMsListView
### Description
A SwiftUI view that renders a list of direct message conversations. It requires an event handler to respond to user interactions such as selecting a channel.
### Usage
```swift
WhopDMsListView { event in
switch event {
case let .channelSelected(channel):
// Handle channel selection
}
}
```
### DMChannel Properties
- **id** (String) - Unique identifier for the channel
- **name** (String) - Display name of the channel
- **isGroup** (Bool) - Indicates if the channel is a group chat
- **isUnread** (Bool) - Indicates if there are unread messages
- **lastMessageText** (String?) - Content of the last message
- **lastMessageCreatedAt** (Date) - Timestamp of the last message
- **isSupportTicket** (Bool) - Indicates if the channel is a support ticket
```
--------------------------------
### Define DMChannel Properties
Source: https://github.com/whopio/whopsdk-elements-swift/blob/main/README.md
The data structure representing a direct message channel.
```swift
public struct DMChannel: Identifiable, Hashable {
public let id: String
public let name: String
public let isGroup: Bool
public let isUnread: Bool
public let lastMessageText: String?
public let lastMessageCreatedAt: Date
public let isSupportTicket: Bool
}
```
--------------------------------
### Track Authentication State
Source: https://github.com/whopio/whopsdk-elements-swift/blob/main/README.md
Use the whopAuthState modifier to observe the current authentication status of the user.
```swift
@State private var isAuthenticated = false
var body: some View {
MyView()
.whopAuthState($isAuthenticated)
}
```
--------------------------------
### Define ChatEvent Enum
Source: https://github.com/whopio/whopsdk-elements-swift/blob/main/README.md
Defines the events triggered by user interactions within the chat interface.
```swift
public enum ChatEvent {
case profileTap(username: String, userId: String) // User tapped a profile
case urlTap(url: URL) // User tapped a link
case messageSent(content: String) // User sent a message
}
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.