# iOS SDK インタースティシャル広告

WARNING

インタースティシャル広告の提供は終了しました

# はじめに

開発環境にXcodeを使用することを前提とします。

# 対応バージョン

iOS 12.0以降

# 導入の流れ

  1. SDKをインストールします
  2. 例を参考に広告表示の実装を行います

# 1. SDKをインストールする

iOS SDK Getting Started / バナー広告からご確認ください。

# 2. 広告表示を実装する

  1. 広告を表示するViewやViewController等のヘッダーファイル内でADG/ADGInterstitial.hをインポートします。
  2. ADGInterstitialクラスのインスタンスを生成します。
  3. delegateメソッドを実装します。
  4. 最前面にあるUIViewControllerをrootViewControllerにセットします。
  5. 任意のタイミングで広告リクエストpreloadを行います。
  6. ADGManagerViewControllerReceiveAdにて広告取得に成功したら広告表示 showを行います。
  7. ViewControllerのdeallocで、インスタンスの破棄をします。
    delegateへのnilセットを忘れないようご注意ください。
import UIKit
import ADG

class InterstitialAdsSwiftViewController: UIViewController {

    private var interstitial: ADGInterstitial?

    override func viewDidLoad() {
        super.viewDidLoad()

        interstitial = ADGInterstitial()
        interstitial?.setLocationId("48549")    // 管理画面から払い出された広告枠ID
        interstitial?.delegate = self
        interstitial?.rootViewController = self
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @IBAction func didTapPreloadButton(_ sender: Any) {
        // 広告リクエスト
        interstitial?.preload()
    }

    @IBAction func didTapShowButton(_ sender: Any) {
        // 広告表示
        interstitial?.show()
    }

    override func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
        // 広告非表示
        interstitial?.dismiss()
    }

}

extension InterstitialAdsSwiftViewController: ADGInterstitialDelegate {

    func adgManagerViewControllerReceiveAd(_ adgManagerViewController: ADGManagerViewController!) {
        print("Received an ad.")
    }

    func adgManagerViewControllerFailed(toReceiveAd adgManagerViewController: ADGManagerViewController!, code: kADGErrorCode) {
        print("Failed to receive an ad.")
        // エラー時のリトライは特段の理由がない限り必ず記述するようにしてください。
        switch code {
        case .adgErrorCodeNeedConnection, // ネットワーク不通
            .adgErrorCodeExceedLimit, // エラー多発
            .adgErrorCodeNoAd: // 広告レスポンスなし
            break
        default:
            adgManagerViewController.loadRequest()
        }
    }

    func adgManagerViewControllerDidTapAd(_ adgManagerViewController: ADGManagerViewController!) {
        print("Did tap ad.")
    }

    func adgInterstitialClose() {
        print("Closed interstitial ads")
    }

}

# 各メソッドの仕様やオプションについて

iOSリファレンスをご参照ください。

# Delegateについて

# 広告受信
func adgManagerViewControllerReceiveAd(_ adgManagerViewController: ADGManagerViewController!)

広告のロードが成功したタイミングで呼び出されます。
ローテーションによる広告取得成功の際にも呼び出されます。

# 広告受信失敗
func adgManagerViewControllerFailed(toReceiveAd adgManagerViewController: ADGManagerViewController!, code: kADGErrorCode)

広告のロードに失敗したタイミングで呼び出されます。

  • kADGErrorCodeUnknown……不明なエラーが発生しました。
  • kADGErrorCodeCommunicationError……アドサーバー間通信/連携しているアドネットワークSDKとの接続等でエラーが発生しました。
  • kADGErrorCodeReceivedFiller……白板検知されました。
  • kADGErrorCodeNoAd……接続先アドネットワークすべて広告在庫切れが返却されました。
  • kADGErrorCodeNeedConnection……デバイスがネットワークに接続されていません。
  • kADGErrorCodeExceedLimit……エラー回数が上限に達しました。
  • kADGErrorCodeTemplateFailed……サイズ指定の誤りなどの要因により広告の形成に失敗しました。
# 広告タップ
func adgManagerViewControllerDidTapAd(_ adgManagerViewController: ADGManagerViewController!)

広告がタップされた際に呼び出されます。
(ブラウザやストア起動の成否は問いません)

# 広告表示終了
func adgInterstitialClose()

広告を閉じたタイミングで呼び出されます。

アプリ内で複数のUIWindowインスタンスが解放されず残っている場合、このタイミングで表示を整理する必要があります。

# デフォルトデザイン

setBackgroundTypeおよびsetCloseButtonTypeで指定できるデフォルトのデザインは以下の通りです。

BackgroundType CloseButtonType Design
0 0
1 1
2 2
3 3
4 4

# カスタムデザイン

オリジナルの画像を適用する場合は下記のルールに準拠してください。

# サイズ

  • 閉じるボタン:横300px/縦30px
  • 背景:横315px/縦300px

縦横比率固定であれば高解像度でも問題ありません。

# ファイル名

  • 閉じるボタン:adg_interstitial_close_button_XXX.png
  • 背景:adg_interstitial_background_XXX.png

XXXには100以降の3桁の数を入れてください。
この数がパーツ番号となります。

# デザインの適用

interstitial.setBackgroundType(XXX)
interstitial.setCloseButtonType(XXX)

XXXにはパーツ番号を記入してください。

# 審査完了前の稼働確認について

審査完了前に広告の掲載イメージをご確認頂く際は、以下のIDに置き換えご確認ください。
このIDをセットしたままアプリをリリースしないようご注意ください。

サイズ テストID 配信広告
インタースティシャル 48549 テスト広告
Last Updated: 4/17/2025, 2:49:53 AM