Skip to content

AdExchangeインタースティシャル広告の導入

tateo-okubo edited this page Sep 12, 2019 · 22 revisions

対応OS

adstir SDK 2.12.0以降をお使いの場合はiOS 8.0以上の端末に配信されます。 adstir SDK 2.12.0未満をお使いの場合はiOS 6.1以上の端末に配信されます。(iOS 8.0以上推奨です)

Google Mobile Ads SDKは7.28.0以上をご利用ください

SDK 2.10.0以降をご利用で、AdExchangeインタースティシャル広告と動画リワード広告を併用している皆さまへ

SDK 2.10.0以降の動画リワード広告と、AdExcahngeインタースティシャル広告をアプリ内で併用した場合、広告の再生ができない場合がございます。 動画リワード広告とAdExcahngeインタースティシャル広告を併用なさる場合は、こちらより、Ad Unit IDに紐づくadstirの枠Noを同時に初期化をするようにお願いします。

初期設定

adstir SDKを導入する

初期設定をご覧になり、adstir SDKをプロジェクトへ導入してください。 対応提携ネットワークを導入する場合はこちらを参考に対応提携ネットワークを導入してください。

GoogleMobileAdsを導入する

adstir SDKと、対応提携ネットワークを導入後、以下の手順でGoogleMobileAdsを導入します。

  • 手動でSDKを導入していた場合

    1. GoogleMobileAds.frameworklibAdMobMediationAdapter-AdstirAds.aを、プロジェクト内の任意の箇所にドラッグ&ドロップします。
    2. Copy items if neededにチェックを入れます。
    3. Add to targets欄で、adstir SDKを利用するすべてのターゲットにチェックを入れます。
    4. Finishをクリックします。
  • CocoaPodsを利用して導入していた場合

    • pod 'AdStir-Ads-SDK-VideoAdSDKBundled/AdMob-MediationAdapter', :path => 'AdstirAdsSdkiOS-x.x.x-VideoAdSDKBundled' を追加します。

CocoaPodsの例

# Uncomment the next line to define a global platform for your project
platform :ios, "8.0"
pod 'AdStir-Ads-SDK-VideoAdSDKBundled/All-Interstitial', :path => 'AdstirAdsSdkiOS-x.x.x-VideoAdSDKBundled'
pod 'AdStir-Ads-SDK-VideoAdSDKBundled/AdMob-MediationAdapter', :path => 'AdstirAdsSdkiOS-x.x.x-VideoAdSDKBundled'
target 'projectname' do
  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
  # use_frameworks!

  # Pods for projectname

end

SDKの実装

Swift

ViewController.swift

// 下記のインポートが必要です
import GoogleMobileAds

class ViewController: UIViewController, GADInterstitialDelegate {
    var interstitial: DFPInterstitial!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // 実際に使用するAd Unit Idは営業担当者から別途お知らせ致します。
        interstitial = DFPInterstitial(adUnitID: "xxxxxxxxxxxxxxxxxxxxxxxx")
        // デリゲートは必要に応じて実装してください
        // See also: https://developers.google.com/mobile-ads-sdk/docs/dfp/ios/ad-events#gadinterstitialdelegate_implementation
        interstitial.delegate = self
        interstitial.load(DFPRequest())
    }

    // MARK: -
    // MARK: GADInterstitialDelegate
    
    func interstitialDidReceiveAd(_ ad: GADInterstitial!){
        interstitial.present(fromRootViewController: self)
    }
    
    func interstitial(_ ad: GADInterstitial!, didFailToReceiveAdWithError error: GADRequestError!) {}
    
    func interstitialWillPresentScreen(_ ad: GADInterstitial!) {}
    
    func interstitialDidFail(toPresentScreen ad: GADInterstitial!) {}
    
    func interstitialWillDismissScreen(_ ad: GADInterstitial!) {}
    
    func interstitialDidDismissScreen(_ ad: GADInterstitial!) {}
    
    func interstitialWillLeaveApplication(_ ad: GADInterstitial!) {}
}

Objective-C

ViewController.m

// 下記のインポートが必要です
@import GoogleMobileAds;

@interface ViewController () <GADInterstitialDelegate>
@property(nonatomic, strong) DFPInterstitial *interstitial;
@end

@implementation ViewController

- (void)viewDidLoad
{
    // 実際に使用するAd Unit Idは営業担当者から別途お知らせ致します。
    self.interstitial = [[DFPInterstitial alloc] initWithAdUnitID:@"xxxxxxxxxxxxxxxxxxxxxxxx"];
    // デリゲートは必要に応じて実装してください
    // See also: https://developers.google.com/mobile-ads-sdk/docs/dfp/ios/ad-events#gadinterstitialdelegate_implementation
    self.interstitial.delegate = self;
    [self.interstitial loadRequest:[DFPRequest request]];
}

// MARK: -
// MARK: GADInterstitialDelegate

- (void)interstitialDidReceiveAd:(GADInterstitial *)ad
{
    [self.interstitial presentFromRootViewController:self];
}

- (void)interstitial:(GADInterstitial *)ad didFailToReceiveAdWithError:(GADRequestError *)error {}

- (void)interstitialWillPresentScreen:(GADInterstitial *)ad {}

- (void)interstitialDidFailToPresentScreen:(GADInterstitial *)ad {}

- (void)interstitialWillDismissScreen:(GADInterstitial *)ad {}

- (void)interstitialDidDismissScreen:(GADInterstitial *)ad {}

- (void)interstitialWillLeaveApplication:(GADInterstitial *)ad {}

@end
Clone this wiki locally