> ## 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.

# Examples

> Check out integration methods and basic usage of the iOS SDK with real code examples.

## GitHub Repository

<Card title="iOS SDK Example" icon="github" href="https://github.com/OpenRhapsody/adrop-ads-example-ios">
  iOS SDK example project
</Card>

***

## Example Project Structure

We provide examples in three different approaches: SwiftUI, UIKit, and Objective-C.

<Tabs>
  <Tab title="SwiftUI">
    Available in the `adrop-ads-example-ios-swiftUI/` folder.

    This is an example implementing ads with SwiftUI-based declarative UI.
  </Tab>

  <Tab title="UIKit">
    Available in the `adrop-ads-example-ios/` folder.

    This is an example implementing ads with UIKit-based traditional approach.
  </Tab>

  <Tab title="Objective-C">
    Available in the `adrop-ads-example-ios-objective-c/` folder.

    This is an example implementing ads with Objective-C.
  </Tab>
</Tabs>

***

## How to Run Examples

<Steps>
  <Step title="Clone the repository">
    ```bash theme={null}
    git clone https://github.com/OpenRhapsody/adrop-ads-example-ios.git
    cd adrop-ads-example-ios
    ```
  </Step>

  <Step title="Install dependencies">
    ```bash theme={null}
    pod install
    ```
  </Step>

  <Step title="Open workspace">
    ```bash theme={null}
    open adrop-ads-example-ios.xcworkspace
    ```

    <Warning>
      You must open `.xcworkspace`, not `.xcodeproj`.
    </Warning>
  </Step>

  <Step title="Run">
    1. Select a simulator or real device
    2. Click **Run** (⌘R)
  </Step>
</Steps>

<Note>
  The example project uses test unit IDs, so you can run it immediately without any additional configuration.
</Note>

***

## Key Example Code

### Banner Ad (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)
    }
}
```

### Interstitial Ad (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)")
    }
}
```

### Interstitial Ad (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
```

***

### User Event Tracking

```swift theme={null}
import AdropAds

class EventTrackingExample {
    func trackEvents() {
        // Simple event - no parameters
        AdropMetrics.sendEvent(name: "app_open")

        // Event with parameters
        AdropMetrics.sendEvent(name: "view_item", params: [
            "item_id": "SKU-123",
            "item_name": "Widget",
            "item_category": "Electronics",
            "price": 29.99
        ])

        // Multi-item event (purchase)
        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]
            ]
        ])

        // Sign up event
        AdropMetrics.sendEvent(name: "sign_up", params: [
            "method": "google"
        ])
    }
}
```

***

## Related Documentation

<CardGroup cols={2}>
  <Card title="Getting Started" href="/sdk/ios">
    SDK installation and initialization
  </Card>

  <Card title="Banner Ad" href="/sdk/ios/banner">
    Banner ad implementation
  </Card>

  <Card title="Interstitial Ad" href="/sdk/ios/interstitial">
    Interstitial ad implementation
  </Card>

  <Card title="Reference" href="/sdk/ios/reference">
    API reference
  </Card>
</CardGroup>
