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

概要

スプラッシュ広告は、アプリ起動時のスプラッシュ画面に表示される広告です。アプリのロゴと一緒に広告が表示され、自然なユーザー体験を提供します。

特徴

  • アプリ起動時の自然な広告露出
  • アプリロゴと一緒にブランドイメージを維持
  • 360px × 270px固定サイズ
  • 画像および動画広告に対応
開発環境ではテストユニットIDを使用してください: PUBLIC_TEST_UNIT_ID_SPLASH

広告サイズ

スプラッシュ広告は固定サイズを使用します:
  • サイズ: 360px × 270px (幅 × 高さ)
  • 広告は画面下部に表示され、上部にはアプリロゴが配置されます

実装方法

スプラッシュ広告は、アプリの要件に応じて3つの方法で実装できます:
  1. AdropSplashAdViewControllerの使用 - 最も簡単な方法
  2. AdropSplashAdViewの使用 - カスタムスプラッシュ画面の構成
  3. SwiftUI実装 - SwiftUIアプリで使用

方法1: AdropSplashAdViewControllerの使用

最も簡単な実装方法です。AdropSplashAdViewControllerがスプラッシュ画面を自動的に管理します。

UIKit実装

import AdropAds

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?

    func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {
        // Adrop SDKの初期化
        Adrop.initialize(production: false)

        return true
    }
}

SceneDelegateでスプラッシュ広告を表示

import UIKit
import AdropAds

class SceneDelegate: UIResponder, UIWindowSceneDelegate {
    var window: UIWindow?

    func scene(
        _ scene: UIScene,
        willConnectTo session: UISceneSession,
        options connectionOptions: UIScene.ConnectionOptions
    ) {
        guard let windowScene = (scene as? UIWindowScene) else { return }

        // Windowの設定
        window = UIWindow(windowScene: windowScene)

        // スプラッシュ広告ビューコントローラの生成
        let splashViewController = AdropSplashAdViewController(
            unitId: "YOUR_SPLASH_UNIT_ID",
            logoImage: UIImage(named: "app_logo")  // アプリロゴ画像
        )
        splashViewController.delegate = self

        // 表示時間の設定 (オプション、デフォルト5秒)
        splashViewController.displayDuration = 3.0

        // スプラッシュ画面をルートに設定
        window?.rootViewController = splashViewController
        window?.makeKeyAndVisible()
    }
}

デリゲートの実装

// MARK: - AdropSplashAdDelegate
extension SceneDelegate: AdropSplashAdDelegate {
    // スプラッシュ広告終了 (必須)
    func onAdClose(impressed: Bool) {
        print("スプラッシュ広告終了 - 表示: \(impressed)")

        // メイン画面に遷移
        let mainViewController = MainViewController()
        window?.rootViewController = mainViewController
    }

    // 広告受信成功 (オプション)
    func onAdReceived(_ ad: AdropSplashAd) {
        print("スプラッシュ広告受信成功")
    }

    // 広告受信失敗 (オプション)
    func onAdFailedToReceive(_ ad: AdropSplashAd, _ errorCode: AdropErrorCode) {
        print("スプラッシュ広告受信失敗: \(errorCode)")
        // 広告失敗時もメイン画面に遷移します
    }

    // 広告表示 (オプション)
    func onAdImpression(_ ad: AdropSplashAd) {
        print("スプラッシュ広告表示")
    }
}
AdropSplashAdViewControllerは広告の読み込み、表示、タイマー管理を自動的に処理します。広告が読み込まれなくても自動的にonAdCloseが呼び出され、メイン画面に遷移します。

方法3: SwiftUI実装

SwiftUIアプリでスプラッシュ広告を実装する方法です。

SwiftUI Wrapper

import SwiftUI
import AdropAds

struct SplashAdView: UIViewControllerRepresentable {
    let unitId: String
    let logoImage: UIImage?
    @Binding var isPresented: Bool

    func makeUIViewController(context: Context) -> AdropSplashAdViewController {
        let controller = AdropSplashAdViewController(
            unitId: unitId,
            logoImage: logoImage
        )
        controller.delegate = context.coordinator
        return controller
    }

    func updateUIViewController(_ uiViewController: AdropSplashAdViewController, context: Context) {
        // 更新不要
    }

    func makeCoordinator() -> Coordinator {
        Coordinator(isPresented: $isPresented)
    }

    class Coordinator: NSObject, AdropSplashAdDelegate {
        @Binding var isPresented: Bool

        init(isPresented: Binding<Bool>) {
            _isPresented = isPresented
        }

        func onAdClose(impressed: Bool) {
            print("スプラッシュ広告終了 - 表示: \(impressed)")
            DispatchQueue.main.async {
                self.isPresented = false
            }
        }

        func onAdReceived(_ ad: AdropSplashAd) {
            print("スプラッシュ広告受信成功")
        }

        func onAdFailedToReceive(_ ad: AdropSplashAd, _ errorCode: AdropErrorCode) {
            print("スプラッシュ広告受信失敗: \(errorCode)")
        }

        func onAdImpression(_ ad: AdropSplashAd) {
            print("スプラッシュ広告表示")
        }
    }
}

SwiftUI Appで使用

import SwiftUI
import AdropAds

@main
struct MyApp: App {
    init() {
        // SDKの初期化
        Adrop.initialize(production: false)
    }

    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

struct ContentView: View {
    @State private var showSplash = true

    var body: some View {
        ZStack {
            if showSplash {
                SplashAdView(
                    unitId: "YOUR_SPLASH_UNIT_ID",
                    logoImage: UIImage(named: "app_logo"),
                    isPresented: $showSplash
                )
                .ignoresSafeArea()
            } else {
                MainView()
            }
        }
    }
}

struct MainView: View {
    var body: some View {
        NavigationView {
            VStack {
                Text("メイン画面")
                    .font(.largeTitle)
            }
            .navigationTitle("ホーム")
        }
    }
}

次のステップ