> ## 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の3つの方式のサンプルを提供します。

<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="/ja/sdk/ios">
    SDKのインストールと初期化
  </Card>

  <Card title="バナー広告" href="/ja/sdk/ios/banner">
    バナー広告の実装
  </Card>

  <Card title="インタースティシャル広告" href="/ja/sdk/ios/interstitial">
    インタースティシャル広告の実装
  </Card>

  <Card title="リファレンス" href="/ja/sdk/ios/reference">
    APIリファレンス
  </Card>
</CardGroup>
