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

> ## Agent Instructions
> Treat these docs and the Whop MCP server as the source of truth for Whop API behavior. Don't infer endpoint behavior from marketing pages.
> MCP server: connect https://mcp.whop.com/mcp (streamable HTTP, browser sign-in, no API key in the client config) to search these docs and read or change live Whop data. Setup: https://docs.whop.com/developer/guides/ai_and_mcp.md
> Whop CLI: install with `curl -fsSL https://whop.com/install.sh | sh` to scaffold, run, and deploy Whop apps and websites. It acts on production, not the sandbox. Overview: https://docs.whop.com/cli/overview.md Agent mode: https://docs.whop.com/cli/agent-mode.md
> Hosting: Whop serves a site or app from the build `whop apps deploy` uploads, with rollbacks, secrets, and server logs. Guide: https://docs.whop.com/developer/websites/hosting.md
> Plugins: in Claude Code, run `/plugin marketplace add whopio/plugins`, then `/plugin install whop@whop`. Guide: https://docs.whop.com/developer/guides/plugins/claude-code.md Every agent tool: https://docs.whop.com/developer/ai/overview.md
> Environments: build and test in the sandbox (API `https://sandbox-api.whop.com/api/v1`, keys at https://sandbox.whop.com/dashboard/developer, SDK environment `Sandbox`; no real money). Production (API `https://api.whop.com/api/v1`, keys at https://whop.com/dashboard/developer, SDK environment `Production`, the SDK default) moves real money, so use it only at launch. The two share no accounts, keys, products, or webhooks, and their keys look identical: never mix them. Sandbox guide: https://docs.whop.com/developer/guides/sandbox.md Comparison: https://docs.whop.com/developer/quickstart.md
> API: send `Authorization: Bearer <API_KEY>` from your server only, and pin a dated version with the `Api-Version-Date` header. OpenAPI spec: https://api.whop.com/api/v1/openapi.json
> Which API: build on the Current API, whose pages live under https://docs.whop.com/api-reference/ (start at https://docs.whop.com/api-reference/overview.md). Pages under /api-reference/legacy/ are the Legacy API. Use one only when https://docs.whop.com/api-reference/stability.md lists the resource as Legacy-only.

# 이용 권한 확인하기

> hasAccess(to:) 또는 isSubscribed로 iOS 프리미엄 콘텐츠 접근을 제한하고, 활성 멤버십을 나열하고, 사용자 로그인 및 로그아웃으로 기기를 동기화하고, 게스트 구매를 지원하세요.

이 가이드는 사용자에게 활성 구독이 있는지 확인하고 그에 따라 프리미엄 콘텐츠 접근을 제한하는 방법을 보여줍니다. 또한 사용자 로그인/로그아웃을 처리하여 여러 기기 간에 구독을 동기화하는 방법도 알아봅니다.

## 배울 내용

* 사용자가 상품에 접근할 수 있는지 확인하기
* 구독 상태에 따라 콘텐츠 접근 제한하기
* 사용자 로그인으로 여러 기기 간 구독 동기화하기

## 사전 요구 사항

* [SDK 설치하기](https://docs.whop.com/ko/developer/guides/ios/installation.md)
* [SDK 구성하기](https://docs.whop.com/ko/developer/guides/ios/build-a-paywall.md#step-1-configure-the-sdk)

## 구독 상태 확인하기

`hasAccess(to:)`를 사용해 사용자가 특정 상품에 접근할 수 있는지 확인하세요:

```swift theme={null}
struct ContentView: View {
    @Environment(Checkout.self) var checkout

    var body: some View {
        VStack {
            // Basic features always available
            BasicFeaturesView()

            // Premium features for subscribers
            if checkout.hasAccess(to: "prod_xxxxxxxxxxxxxx") {
                PremiumFeaturesView()
            }

            // If you have multiple tiers, check each product separately
            if checkout.hasAccess(to: "prod_yyyyyyyyyyyyyy") {
                EnterpriseFeaturesView()
            }
        }
    }
}
```

또는 `isSubscribed`를 사용해 사용자에게 활성 구독이 있는지 확인하세요:

```swift theme={null}
if checkout.isSubscribed {
    // User has at least one active membership
}
```

## 활성 멤버십 보기

`memberships` 배열에 접근하여 구독 세부 정보를 표시하세요:

```swift theme={null}
struct SubscriptionStatusView: View {
    @Environment(Checkout.self) var checkout

    var body: some View {
        List {
            if checkout.memberships.isEmpty {
                Text("No active subscriptions")
                    .foregroundStyle(.secondary)
            } else {
                ForEach(checkout.memberships) { membership in
                    MembershipRow(membership: membership)
                }
            }
        }
    }
}

struct MembershipRow: View {
    let membership: CheckoutMembership

    var body: some View {
        VStack(alignment: .leading) {
            Text("Subscription")
                .font(.headline)

            if let expiresAt = membership.expiresAt {
                Text("Renews \(expiresAt, style: .date)")
                    .foregroundStyle(.secondary)
            }

            Text("Status: \(membership.status.rawValue)")
                .font(.caption)
                .foregroundStyle(.secondary)
        }
    }
}
```

## 사용자 로그인 및 로그아웃

사용자 ID를 사용하면 여러 기기 간에 구독을 동기화할 수 있습니다. 사용자가 로그인하면 SDK는 현재 기기에서 아직 귀속되지 않은 멤버십을 자동으로 귀속시키고 기존 멤버십을 불러옵니다.

### 사용자 로그인하기

```swift theme={null}
func handleLogin(userId: String) async {
    do {
        try await checkout.logIn(appUserId: userId)
        // Memberships are now synced for this user
    } catch {
        print("Login failed: \(error)")
    }
}
```

### 사용자 로그아웃하기

```swift theme={null}
func handleLogout() {
    checkout.logOut()
    // User is now logged out, memberships cleared
}
```

### 현재 사용자 확인하기

```swift theme={null}
if let userId = checkout.appUserId {
    Text("Logged in as \(userId)")
} else {
    Text("Not logged in")
}
```

## 게스트 구매

사용자는 로그인하지 않고도 구독을 구매할 수 있습니다. SDK는 이러한 구매를 기기 ID로 추적하고 사용자가 로그인하면 자동으로 귀속시킵니다.

```swift theme={null}
struct PurchaseFlow: View {
    @Environment(Checkout.self) var checkout
    @State private var showingLogin = false

    var body: some View {
        VStack {
            if checkout.appUserId == nil {
                // User not logged in - they can still purchase
                Text("Purchase as guest or log in to sync across devices")

                Button("Continue as Guest") {
                    // Purchase will be tied to device
                    Task { try? await checkout.purchase("plan_xxx") }
                }

                Button("Log In") {
                    showingLogin = true
                }
            } else {
                // User logged in - purchase tied to their account
                Button("Subscribe") {
                    Task { try? await checkout.purchase("plan_xxx") }
                }
            }
        }
        .sheet(isPresented: $showingLogin) {
            // Your login view here
        }
    }
}
```

## 전체 예제

다음은 사용자 인증과 함께 이용 권한을 확인하는 전체 예제입니다:

```swift theme={null}
struct MainView: View {
    @Environment(Checkout.self) var checkout
    @State private var showingPaywall = false
    @State private var showingLogin = false

    var body: some View {
        NavigationStack {
            Group {
                if !checkout.isInitialized {
                    ProgressView("Loading...")
                } else if checkout.hasAccess(to: "prod_xxxxxxxxxxxxxx") {
                    PremiumContentView()
                } else {
                    FreeContentView(onUpgrade: { showingPaywall = true })
                }
            }
            .toolbar {
                ToolbarItem(placement: .topBarTrailing) {
                    Menu {
                        if let userId = checkout.appUserId {
                            Text("Signed in as \(userId)")
                            Button("Sign Out", action: signOut)
                        } else {
                            Button("Sign In") { showingLogin = true }
                        }

                        Divider()

                        if checkout.hasAccess(to: "prod_xxxxxxxxxxxxxx") {
                            Button("Manage Subscription") {
                                // Show subscription management
                            }
                        }
                    } label: {
                        Image(systemName: "person.circle")
                    }
                }
            }
            .sheet(isPresented: $showingPaywall) {
                PaywallView()
            }
            .sheet(isPresented: $showingLogin) {
                LoginView { userId in
                    Task {
                        try? await checkout.logIn(appUserId: userId)
                        showingLogin = false
                    }
                }
            }
        }
    }

    func signOut() {
        checkout.logOut()
    }
}

struct FreeContentView: View {
    let onUpgrade: () -> Void

    var body: some View {
        VStack(spacing: 20) {
            Text("Free Content")
                .font(.title)

            Text("Upgrade to access premium features")
                .foregroundStyle(.secondary)

            Button("Upgrade Now", action: onUpgrade)
                .buttonStyle(.borderedProminent)
        }
    }
}

struct PremiumContentView: View {
    var body: some View {
        VStack {
            Image(systemName: "crown.fill")
                .font(.largeTitle)
                .foregroundStyle(.yellow)

            Text("Premium Content")
                .font(.title)

            Text("Thanks for subscribing!")
        }
    }
}
```

## 반응형 업데이트

SDK는 구독 상태가 바뀌면 자동으로 뷰를 업데이트합니다. `Checkout`은 `@Observable`이므로, `@Environment(Checkout.self)`를 사용하는 모든 뷰는 다음과 같은 경우 다시 렌더링됩니다:

* 구매가 완료될 때
* 사용자가 로그인하거나 로그아웃할 때
* SDK가 멤버십을 불러오거나 업데이트할 때

수동으로 새로 고칠 필요가 없습니다.

## 다음 단계

> [card] [페이월 만들기](https://docs.whop.com/ko/developer/guides/ios/build-a-paywall.md)
>
> 변형을 표시하고 구매를 처리하세요

> [card] [API 레퍼런스](https://docs.whop.com/ko/developer/guides/ios/checkout-reference.md)
>
> 사용 가능한 모든 메서드와 속성을 살펴보세요


## Related topics

- [iOS Checkout SDK](https://docs.whop.com/ko/developer/guides/ios/overview.md)
- [Whop iOS SDK 설치하기](https://docs.whop.com/ko/developer/guides/ios/installation.md)
- [iOS 페이월 만들기](https://docs.whop.com/ko/developer/guides/ios/build-a-paywall.md)
