Skip to content

Interstitial_Ad_iOS

AdGeneration edited this page Jul 19, 2018 · 17 revisions

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

はじめに

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

対応バージョン

iOS 7.0以降

導入の流れ

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

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

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

2. 広告表示を実装する

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

@interface InterstitialAdsObjCViewController () <ADGInterstitialDelegate>

@property (nonatomic) ADGInterstitial *interstitial;

@end

@implementation InterstitialAdsObjCViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.interstitial = [[ADGInterstitial alloc] init];
    [self.interstitial setLocationId:@"48549"]; // 管理画面から払い出された広告枠ID
    self.interstitial.delegate = self;
}

- (IBAction)didTapPreloadButton:(id)sender {
    // 広告リクエスト
    [self.interstitial preload];
}

- (IBAction)didTapShowButton:(id)sender {
    // 広告表示
    [self.interstitial show];
}

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    // 広告非表示
    [self.interstitial dismiss];
}

- (void)dealloc {
    self.interstitial.delegate = nil;
    self.interstitial = nil;
}

- (void)ADGManagerViewControllerReceiveAd:(ADGManagerViewController *)adgManagerViewController {
    NSLog(@"Received an ad.");
}

- (void)ADGManagerViewControllerFailedToReceiveAd:(ADGManagerViewController *)adgManagerViewController
                                             code:(kADGErrorCode)code {
    NSLog(@"Failed to receive an ad.");
    // エラー時のリトライは特段の理由がない限り必ず記述するようにしてください。
    switch (code) {
        case kADGErrorCodeNeedConnection:   // ネットワーク不通
        case kADGErrorCodeExceedLimit:      // エラー多発
        case kADGErrorCodeNoAd:             // 広告レスポンスなし
            break;
        default:
            [adgManagerViewController loadRequest];
            break;
    }
}

- (void)ADGManagerViewControllerDidTapAd:(ADGManagerViewController *)adgManagerViewController {
    NSLog(@"Did tap ad.");
}

- (void)ADGInterstitialClose {
    NSLog(@"Closed interstitial ads.");
}

@end

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

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

Delegateについて

広告受信
- (void)ADGManagerViewControllerReceiveAd:(ADGManagerViewController *)adgManagerViewController

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

広告受信失敗
- (void)ADGManagerViewControllerFailedToReceiveAd:(ADGManagerViewController *)adgManagerViewController code:(kADGErrorCode)code

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

  • kADGErrorCodeUnknown……不明なエラーが発生しました。
  • kADGErrorCodeCommunicationError……アドサーバー間通信/連携しているアドネットワークSDKとの接続等でエラーが発生しました。
  • kADGErrorCodeReceivedFiller……白板検知されました。
  • kADGErrorCodeNoAd……接続先アドネットワーク全て広告在庫切れが返却されました。
  • kADGErrorCodeNeedConnection……デバイスがネットワークに接続されていません。
  • kADGErrorCodeExceedLimit……エラー回数が上限に達しました。
広告タップ
- (void)ADGManagerViewControllerDidTapAd:(ADGManagerViewController *)adgManagerViewController

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

広告表示終了
- (void)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にはパーツ番号を記入してください。

Swiftでの実装

広告の呼び出しを実装します。

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
    }

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

}

Home

導入マニュアルのドキュメントはコチラに移行しました。

お手数ですがリンクから遷移してください。 https://docs.sdk.ad-generation.jp/

Clone this wiki locally