メインコンテンツへスキップ

GitHubリポジトリ

iOS SDK Example

iOS SDKサンプルプロジェクト

サンプルプロジェクト構造

SwiftUI、UIKit、Objective-Cの3つの方式のサンプルを提供します。
adrop-ads-example-ios-swiftUI/フォルダで確認できます。SwiftUIベースの宣言的UIで広告を実装するサンプルです。

サンプルの実行方法

1

リポジトリのクローン

git clone https://github.com/OpenRhapsody/adrop-ads-example-ios.git
cd adrop-ads-example-ios
2

依存関係のインストール

pod install
3

ワークスペースを開く

open adrop-ads-example-ios.xcworkspace
.xcodeprojではなく.xcworkspaceを開く必要があります。
4

実行

  1. シミュレーターまたは実機を選択
  2. Run (⌘R) を実行
サンプルプロジェクトはテストユニットIDを使用しているため、別途設定なしですぐに実行できます。

主なサンプルコード

バナー広告 (SwiftUI)

import SwiftUI
import AdropAds

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

インタースティシャル広告 (UIKit)

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)

@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

ユーザーイベントトラッキング

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"
        ])
    }
}

関連ドキュメント