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

# 예제

> iOS SDK 연동 방법과 기본 사용법을 실제 코드로 확인할 수 있습니다.

## GitHub 레포지토리

<Card title="iOS SDK Example" icon="github" href="https://github.com/OpenRhapsody/adrop-ads-example-ios">
  iOS SDK 예제 프로젝트
</Card>

***

## 예제 프로젝트 구조

SwiftUI, UIKit, Objective-C 세 가지 방식의 예제를 제공합니다.

<Tabs>
  <Tab title="SwiftUI">
    `adrop-ads-example-ios-swiftUI/` 폴더에서 확인할 수 있습니다.

    SwiftUI 기반의 선언적 UI로 광고를 구현하는 예제입니다.
  </Tab>

  <Tab title="UIKit">
    `adrop-ads-example-ios/` 폴더에서 확인할 수 있습니다.

    UIKit 기반의 전통적인 방식으로 광고를 구현하는 예제입니다.
  </Tab>

  <Tab title="Objective-C">
    `adrop-ads-example-ios-objective-c/` 폴더에서 확인할 수 있습니다.

    Objective-C로 광고를 구현하는 예제입니다.
  </Tab>
</Tabs>

***

## 예제 실행 방법

<Steps>
  <Step title="레포지토리 클론">
    ```bash theme={null}
    git clone https://github.com/OpenRhapsody/adrop-ads-example-ios.git
    cd adrop-ads-example-ios
    ```
  </Step>

  <Step title="의존성 설치">
    ```bash theme={null}
    pod install
    ```
  </Step>

  <Step title="워크스페이스 열기">
    ```bash theme={null}
    open adrop-ads-example-ios.xcworkspace
    ```

    <Warning>
      `.xcodeproj`가 아닌 `.xcworkspace`를 열어야 합니다.
    </Warning>
  </Step>

  <Step title="실행">
    1. 시뮬레이터 또는 실제 디바이스 선택
    2. **Run** (⌘R) 실행
  </Step>
</Steps>

<Note>
  예제 프로젝트는 테스트 유닛 ID를 사용하므로 별도의 설정 없이 바로 실행할 수 있습니다.
</Note>

***

## 주요 예제 코드

### 배너 광고 (SwiftUI)

```swift theme={null}
import SwiftUI
import AdropAds

struct BannerExample: View {
    var body: some View {
        AdropBannerRepresented(unitId: "PUBLIC_TEST_UNIT_ID_320_50")
            .frame(width: 320, height: 50)
    }
}
```

### 전면 광고 (UIKit)

```swift theme={null}
import UIKit
import AdropAds

class InterstitialViewController: UIViewController, AdropInterstitialAdDelegate {
    var interstitialAd: AdropInterstitialAd?

    override func viewDidLoad() {
        super.viewDidLoad()
        interstitialAd = AdropInterstitialAd(unitId: "PUBLIC_TEST_UNIT_ID_INTERSTITIAL")
        interstitialAd?.delegate = self
        interstitialAd?.load()
    }

    func onAdReceived(_ ad: AdropInterstitialAd) {
        if ad.isLoaded {
            ad.show(fromRootViewController: self)
        }
    }

    func onAdFailedToReceive(_ ad: AdropInterstitialAd, _ errorCode: AdropErrorCode) {
        print("Failed: \(errorCode)")
    }
}
```

### 전면 광고 (Objective-C)

```objc theme={null}
@import AdropAds;

@interface InterstitialViewController () <AdropInterstitialAdDelegate>
@property (nonatomic, strong) AdropInterstitialAd *interstitialAd;
@end

@implementation InterstitialViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.interstitialAd = [[AdropInterstitialAd alloc] initWithUnitId:@"PUBLIC_TEST_UNIT_ID_INTERSTITIAL"];
    self.interstitialAd.delegate = self;
    [self.interstitialAd load];
}

- (void)onAdReceived:(AdropInterstitialAd *)ad {
    if (ad.isLoaded) {
        [ad showFromRootViewController:self];
    }
}

- (void)onAdFailedToReceive:(AdropInterstitialAd *)ad :(AdropErrorCode)errorCode {
    NSLog(@"Failed: %ld", (long)errorCode);
}

@end
```

***

### 사용자 이벤트 트래킹

```swift theme={null}
import AdropAds

class EventTrackingExample {
    func trackEvents() {
        // 단순 이벤트 - 파라미터 없음
        AdropMetrics.sendEvent(name: "app_open")

        // 파라미터가 있는 이벤트
        AdropMetrics.sendEvent(name: "view_item", params: [
            "item_id": "SKU-123",
            "item_name": "Widget",
            "item_category": "Electronics",
            "price": 29.99
        ])

        // 다중 아이템 이벤트 (구매)
        AdropMetrics.sendEvent(name: "purchase", params: [
            "tx_id": "tx_123",
            "currency": "KRW",
            "items": [
                ["item_id": "A", "item_name": "Product A", "price": 100, "quantity": 1],
                ["item_id": "B", "item_name": "Product B", "price": 200, "quantity": 2]
            ]
        ])

        // 회원가입 이벤트
        AdropMetrics.sendEvent(name: "sign_up", params: [
            "method": "google"
        ])
    }
}
```

***

## 관련 문서

<CardGroup cols={2}>
  <Card title="시작하기" href="/ko/sdk/ios">
    SDK 설치 및 초기화
  </Card>

  <Card title="배너 광고" href="/ko/sdk/ios/banner">
    배너 광고 구현
  </Card>

  <Card title="전면 광고" href="/ko/sdk/ios/interstitial">
    전면 광고 구현
  </Card>

  <Card title="레퍼런스" href="/ko/sdk/ios/reference">
    API 레퍼런스
  </Card>
</CardGroup>
