SDK の移行

コレクションでコンテンツを整理 必要に応じて、コンテンツの保存と分類を行います。

このページでは、最新バージョンと以前のバージョンへの移行について説明します。

v9 から v10 に移行する

iOS 11 で広告配信が停止

Google Mobile Ads SDK バージョン 10.0.0 が広告を配信する最小の iOS バージョンは iOS 12 です。

Google Mobile Ads SDK バージョン 10.0.0 へのアップグレードによって、iOS 11 および iOS 10 デバイス上でのアプリの破損は発生しませんが、これらのデバイスでは広告が配信されなくなります。

ビットコードによるビルドはサポートされなくなりました

Google Mobile Ads SDK を統合するには、モバイルアプリでビットコードを無効にする必要があります。

タイプを削除しました

タイプ 備考
性別 交換は不要です。
GADMRewardBasedVideoAdNetworkAdapterProtocol ネットワークを選択するに記載されているすべてのリワード メディエーション アダプタで、これらのプロトコルが 1 年以上使用されている。メディエーションとカスタム イベントでは GADMediationAdapter を使用します。
GADMRewardBasedVideoAdNetworkConnectorProtocol

プロパティを削除しました

次のプロパティは置き換えなしで削除されます。

v10.0.0 のクラス プロパティ
GADMediationAdRequest userBirthday
userGender
userHasLocation
userLatitude
userLongitude
userLocationAccuracyInMeters
userLocationDescription
GADCustomEventRequest userHasLocation
userLatitude
userLongitude
userLocationAccuracyInMeters
userLocationDescription

v8 から v9 に移行する

iOS 10 で広告配信が停止

Google Mobile Ads SDK バージョン 9.0.0 がサポートする iOS バージョンは iOS 11 以降です。

Google Mobile Ads SDK バージョン 9.0.0 へのアップグレードによって、iOS 10 デバイス上でアプリの機能が壊れることはありませんが、広告は配信されなくなります。

ステータスバー コントロールの適用強化

バージョン 9.0.0 以降では、全画面フォーマットの広告を表示する際に、広告でステータスバーの表示を制御できるようにする必要があります。それができていない場合は、ログにエラー メッセージが表示されます。

アプリのビュー コントローラのレイアウトによっては、これを実現するために変更を行う必要はありません。広告の rootViewControllermodalPresentationCapturesStatusBarAppearance プロパティと childViewControllerForStatusBarHidden プロパティのどちらを設定する必要があるかを検討してください。

adDoesPresentFullScreenContent の名前を adWillPresentFullScreenContent に変更しました。

動作の変更はありません。デリゲート メソッドは広告が表示される直前に呼び出されるため、新しいメソッド名の方が機能をより正確に反映できます。

GADRequest から Location Setting API を削除

Google が広告をターゲティングする際に位置情報は使われないため、- (void)setLocationWithLatitude:longitude:accuracy:GADRequest から削除されました。第三者広告ネットワークに位置情報を渡す必要がある場合は、サードパーティの API をご利用ください。

カスタム イベント インターフェースのサポート終了

カスタム イベントを使用すると、 AdMob メディエーションを使用している場合に、サポートされている広告ネットワーク以外の広告ネットワーク向けのウォーターフォール メディエーションを追加できます。

すべてのカスタム イベント プロトコルはサポートが終了しました。同じ機能を実現するには、代わりに既存の GADMediationAdapter プロトコルと GADMediationAdEventDelegate プロトコルを使用してください。この変更により明確性が向上し、以前は利用できなかったリワード広告とインタースクローラー広告用のカスタム イベントを作成できるようになりました。

API

下の表は、バージョン 9.0.0 以降で使うべきカスタム イベント API に対応するメディエーション アダプタ API の一覧です。

バージョン 8 バージョン 9
GADCustomEventBanner
GADCustomEvent インタースティシャル
GADCustomEventNativeAd
GADMediationAdapter GADMediationBannerAd
GADMediationInterstitialAd
GADMediationInterscrollerAd
GADMediationRewardedAd
GADMediationNativeAd
delegate デリゲートは、GADMediationAdapter クラスの個々の読み込み関数の読み込み完了ハンドラによって返されます。
-init -init
-requestBannerAd:parameter:label:request: -loadBannerForAdConfiguration:completionHandler:
-requestInterstitialAdWithParameter:label:request: -loadInterstitialForAdConfiguration:completionHandler:
-requestNativeAdWithParameter:request:adTypes:options:rootViewController: -loadNativeAdForAdConfiguration:completionHandler:
なし -loadInterscrollerAdForAdConfiguration:completionHandler:
なし -loadRewardedAdForAdConfiguration:completionHandler:
-presentFromRootViewController: -presentFromViewController:
-handlesUserClicks -handlesUserClicks
-handlesUserImpressions -handlesUserImpressions

デリゲート メソッド

下の表は、バージョン 9.0.0 以降で使うべきカスタム イベント デリゲート メソッドに対応するメディエーション広告イベント デリゲート メソッドの一覧です。

バージョン 8 バージョン 9
GADCustomEventBannerDelegate
GADCustomEventInterstitialDelegate
GADCustomEventNativeAdDelegate
GADMediationAdEventDelegate 目標メディエーション広告
-customEventBanner:didReceiveAd:
-customEventInterstitialDidReceiveAd:
広告の読み込みステータスは、GADMediationAdapter クラスの個々の読み込み関数の読み込み完了ハンドラに含まれます。
-customEventBanner:didFailAd:
-customEventInterstitial:didFailAd:
-customEventBannerWasClicked:
-customEventInterstitialWasClicked:
-reportClick
-customEventBannerWillPresentModal:
-customEventInterstitialWillPresentModal:
-willPresentFullScreenView
-customEventBannerWillDismissModal:
-customEventInterstitialWillDismissModal:
-willDismissFullScreenView
-customEventBannerDidDismissModal:
-customEventInterstitialDidDismissModal:
-didDismissFullScreenView
-customEventBannerWillLeaveApplication:
-customEventInterstitialWillLeaveApplication:
-willBackgroundApplication
viewControllerForPresentingModalView -[GADMediationBannerAd view]

削除または置換されたその他のメソッドと定数

メソッド、定数、プロパティへの変更
kGAD- プレフィックス付き定数 削除しました。GAD- プレフィックス付き定数を使用してください。
GADAdNetworkResponseInfo credentials は削除されました。代わりに adUnitMapping を使用してください。
GAMRequest GAMRequestkGAMSimulatorID が非推奨になりました。代わりに GADRequestConfigurationGADSimulatorID を使用してください。
GADCustomNativeAd GADCustomNativeAdmediaView が非推奨になりました。代わりに mediaContent を使用してください。
GoogleMobileAds の In-App Purchase API GoogleMobileAdsinAppPurchase API は削除されました。

v7 から v8 に移行する

Google Mobile Ads SDKバージョン8.0.0では、APIの名前変更と削除に加えて、いくつかの主要な変更が導入されています。

フルスクリーン形式のAPIアップデート

バージョン8.0.0以降、インタースティシャル広告とリワード広告は、一貫性を高めるために一般的なフルスクリーン広告スタイルを共有しています。これらの新しいフルスクリーン広告APIには、バージョン7のフルスクリーン広告APIとの2つの大きな違いがあります。

  1. 静的クラスメソッドのload

    フルスクリーン広告をロード/表示するための以前のアプローチは次のとおりです。

    1. 広告オブジェクトインスタンスを作成し、そのインスタンスへの参照を保持します。
    2. ロードとショーのコールバックを処理するデリゲートを割り当てます。
    3. 広告を読み込みます。
    4. isReadyを使用して広告が読み込まれるかどうかを確認します。
    5. 広告を表示します。

    バージョン8では、アプローチが少し変更されています。ロードコールバックはデリゲートの一部ではなくなりました。代わりに、それらは完了ハンドラーとしてloadメソッドに渡されます。

    1. 広告クラスで静的ロードメソッドを呼び出し、ロード完了ハンドラーを提供します。
    2. ロード完了コールバックで、返されたロードされた広告への参照を保持します。
    3. showコールバックを処理するデリゲートを割り当てます。
    4. 広告を表示します。

    新しいアプローチには、次の利点があります。

    • ロードされていない広告への参照はありません。
    • 読み込み中に広告オブジェクトを保持する必要はありません。
  2. 一貫した広告イベント。

    イベントタイプ既存のAPI v8 API
    イベントの読み込みGADInterstitialDelegateまたはGADRewardedAdDelegate l10n-placeholder36 LoadCompletionHandlerまたはGADRewardedAdLoadCompletionHandler
    プレゼンテーションイベントGADFullScreenContentDelegate

    以前は、広告イベントをリッスンするには、 GADInterstitialDelegateプロトコルを実装するクラスをインタースティシャルのデリゲートプロパティに登録するか、 GADRewardedAdDelegateプロトコルを実装するクラスを使用しているフォーマットに応じてリワード広告のデリゲートプロパティに登録していました。この同じデリゲートには、広告の読み込みとプレゼンテーションのライフサイクルの両方に関連するメソッドがありました。

    バージョン8では、ロードイベントとプレゼンテーションイベントが別々になっています。広告を読み込む前に単一のデリゲートを設定する必要がなく、広告を表示する前であればいつでもGADFullScreenContentDelegateを登録できるようになりました。各フォーマットに固有の広告ロードイベントは、loadメソッドで渡される単一のロード完了ハンドラーに移動します。

間質性

広告を読み込む

以下のコードスニペットは、インタースティシャル広告をロードし、広告のロードが成功または失敗したときにイベントをリッスンする方法を示しています。

v7

迅速

import GoogleMobileAds
import UIKit

class ViewController: UIViewController, GADInterstitialDelegate {

  var interstitial: GADInterstitial!

  override func viewDidLoad() {
    super.viewDidLoad()
    interstitial = GADInterstitial(adUnitID: "ca-app-pub-3940256099942544/44118910")
    interstitial.delegate = self
    let request = GADRequest()
    interstitial.load(request)
  }

  /// Tells the delegate an ad request succeeded.
  func interstitialDidReceiveAd(_ ad: GADInterstitial) {
    print("Interstitial ad loaded.")
  }

  /// Tells the delegate an ad request failed.
  func interstitial(_ ad: GADInterstitial, didFailToReceiveAdWithError error: GADRequestError) {
    print("Interstitial ad failed to load with error: \(error.localizedDescription)")
  }
}

Objective-C

@import GoogleMobileAds;
@import UIKit;

@interface ViewController () 

@property(nonatomic, strong) GADInterstitial *interstitial;

@end

@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];
  self.interstitial = [[GADInterstitial alloc]
      initWithAdUnitID:@"ca-app-pub-3940256099942544/44118910"];
  self.interstitial.delegate = self;
  GADRequest *request = [GADRequest request];
  [self.interstitial loadRequest:request];
}

/// Tells the delegate an ad request succeeded.
- (void)interstitialDidReceiveAd:(GADInterstitial *)ad {
  NSLog(@"Insterstitial ad loaded.");
}

/// Tells the delegate an ad request failed.
- (void)interstitial:(GADInterstitial *)ad
    didFailToReceiveAdWithError:(GADRequestError *)error {
  NSLog(@"Interstitial ad failed to load with error: %@", [error localizedDescription]);
}

v8

迅速

import GoogleMobileAds
import UIKit

class ViewController: UIViewController, GADFullScreenContentDelegate {

  var interstitial: GADInterstitialAd?

  override func viewDidLoad() {
    super.viewDidLoad()
    let request = GADRequest()
    GADInterstitialAd.load(withAdUnitID:"ca-app-pub-8123415297019784/4985798738",
                                request: request,
                      completionHandler: { (ad, error) in
                        if let error = error {
                          print("Failed to load interstitial ad with error: \(error.localizedDescription)")
                          return
                        }
                        self.interstitial = ad
                        self.interstitial.fullScreenContentDelegate = self
                      }
    )
  }
}

Objective-C

@import GoogleMobileAds;
@import UIKit;

@interface ViewController () 

@property(nonatomic, strong) GADInterstitialAd *interstitial;

@end

@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];
  GADRequest *request = [GADRequest request];
  [GADInterstitialAd loadWithAdUnitID:@"ca-app-pub-3940256099942544/44118910"
                              request:request
                    completionHandler:^(GADInterstitialAd *ad, NSError *error) {
    if (error) {
      NSLog(@"Failed to load interstitial ad with error: %@", [error localizedDescription]);
      return;
    }
    self.interstitial = ad;
    self.interstitial.fullScreenContentDelegate = self;
  }];
}

ディスプレイ広告

v7

迅速

func showInterstitial() {
  ...
  if interstitial.isReady {
    interstitial.present(fromRootViewController: self)
  } else {
    print("Ad wasn't ready")
  }
}

Objective-C

- (void)showInterstitial: {
  ...
  if (self.interstitial.isReady) {
    [self.interstitial presentFromRootViewController:self];
  } else {
    NSLog(@"Ad wasn't ready");
  }
}

v8

迅速

func showInterstitial() {
  ...
  if let ad = interstitial {
    ad.present(fromRootViewController: self)
  } else {
    print("Ad wasn't ready")
  }
}

Objective-C

- (void)showInterstitial: {
  ...
  if (self.interstitial) {
    [self.interstitial presentFromRootViewController:self];
  } else {
    NSLog(@"Ad wasn't ready");
  }
}

プレゼンテーション広告イベント

以下のコードスニペットは、広告が表示されたとき(成功または失敗したとき)と広告が閉じられたときのコールバックを処理する方法を示しています。

v7

迅速

override func viewDidLoad() {
  super.viewDidLoad()
  interstitial = GADInterstitial(adUnitID: "ca-app-pub-3940256099942544/44118910")
  interstitial.delegate = self
  ...
}

/// Tells the delegate that an interstitial will be presented.
func interstitialWillPresentScreen(_ ad: GADInterstitial) {
  print("Interstitial ad will be presented.")
}

/// Tells the delegate the interstitial is to be animated off the screen.
func interstitialWillDismissScreen(_ ad: GADInterstitial) {
  print("Interstitial ad will be dismissed.")
}

/// Tells the delegate the interstitial had been animated off the screen.
func interstitialDidDismissScreen(_ ad: GADInterstitial) {
  print("Interstitial ad dismissed.")
}

/// Tells the delegate that a user click will open another app
/// (such as the App Store), backgrounding the current app.
///
/// This is not a reliable callback for an ad click event and is removed in
/// version 8. If you wish to listen to an ad causing a user to leave the app,
/// use applicationWillResignActive: or sceneWillResignActive: instead.
func interstitialWillLeaveApplication(_ ad: GADInterstitial) {
  print("Interstitial ad will leave application.")
}

Objective-C

- (void)viewDidLoad {
  [super viewDidLoad];
  self.interstitial = [[GADInterstitial alloc] initWithAdUnitID:"ca-app-pub-3940256099942544/44118910"];
  self.interstitial.delegate = self;
  ...
}

/// Tells the delegate that an interstitial will be presented.
- (void)interstitialWillPresentScreen:(GADInterstitial *)ad {
  NSLog(@"Interstitial ad will be presented.");
}

/// Tells the delegate the interstitial is to be animated off the screen.
- (void)interstitialWillDismissScreen:(GADInterstitial *)ad {
  NSLog(@"Interstitial ad will be dismissed.");
}

/// Tells the delegate the interstitial had been animated off the screen.
- (void)interstitialDidDismissScreen:(GADInterstitial *)ad {
  NSLog(@"Interstitial ad dismissed.");
}

/// Tells the delegate that a user click will open another app
/// (such as the App Store), backgrounding the current app.
///
/// This is not a reliable callback for an ad click event and is removed in
/// version 8. If you wish to listen to an ad causing a user to leave the app,
/// use applicationWillResignActive: or sceneWillResignActive: instead.
- (void)interstitialWillLeaveApplication:(GADInterstitial *)ad {
  NSLog(@"Interstitial ad will leave application.");
}

v8

迅速

override func viewDidLoad() {
  super.viewDidLoad()
  let request = GADRequest()
  GADInterstitialAd.load(withAdUnitID:"ca-app-pub-8123415297019784/4985798738",
                              request: request,
                    completionHandler: { (ad, error) in
                      if let error = error {
                        print(error.localizedDescription)
                        return
                      }
                      self.interstitial = ad
                      self.interstitial.fullScreenContentDelegate = self
                    }
  )
}

func adDidPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) {
  print("Ad did present full screen content.")
}

func ad(_ ad: GADFullScreenPresentingAd, didFailToPresentFullScreenContentWithError error: Error) {
  print("Ad failed to present full screen content with error \(error.localizedDescription).")
}

func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) {
  print("Ad did dismiss full screen content.")
}

Objective-C

- (void)viewDidLoad {
  [super viewDidLoad];
  GADRequest *request = [GADRequest request];
  [GADInterstitialAd loadWithAdUnitID:@"ca-app-pub-3940256099942544/44118910"
                              request:request
                    completionHandler:^(GADInterstitialAd *ad, NSError *error) {
    if (error) {
      NSLog(@"interstitial:didFailToReceiveAdWithError: %@", [error localizedDescription])
      return;
    }
    self.interstitial = ad;
    self.interstitial.fullScreenContentDelegate = self;
  }];
}

- (void)adDidPresentFullScreenContent:(id)ad {
  NSLog(@"Ad did present full screen content.");
}

- (void)ad:(id)ad didFailToPresentFullScreenContentWithError:(NSError *)error {
  NSLog(@"Ad failed to present full screen content with error %@.", [error localizedDescription]);
}

- (void)adDidDismissFullScreenContent:(id)ad {
  NSLog(@"Ad did dismiss full screen content.");
}

褒賞

広告を読み込む

v7

迅速

import GoogleMobileAds
import UIKit

class ViewController: UIViewController, GADRewardedAdDelegate {
  /// The rewarded ad.
  var rewardedAd: GADRewardedAd?

  override func viewDidLoad() {
    super.viewDidLoad()
    rewardedAd = GADRewardedAd(adUnitID: "ca-app-pub-3940256099942544/1712485313")
    rewardedAd.delegate = self
    rewardedAd?.load(GADRequest()) { error in
      if let error = error {
        print("Rewarded ad failed to load with error: \(error.localizedDescription)")
      } else {
        print("Rewarded ad loaded.")
      }
    }
  }
}

Objective-C

@import GoogleMobileAds;
@import UIKit;

@interface ViewController () 

@property(nonatomic, strong) GADRewardedAd *rewardedAd;

@end

@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];

  self.rewardedAd = [[GADRewardedAd alloc]
      initWithAdUnitID:@"ca-app-pub-3940256099942544/1712485313"];
  self.rewardedAd.delegate = self;
  GADRequest *request = [GADRequest request];
  [self.rewardedAd loadRequest:request completionHandler:^(GADRequestError * _Nullable error) {
    if (error) {
      NSLog(@"Rewarded ad failed to load with error: %@", [error localizedDescription]);
    } else {
      NSLog(@"Rewarded ad loaded.");
    }
  }];
}

v8

迅速

import GoogleMobileAds
import UIKit

class ViewController: UIViewController, GADFullScreenContentDelegate {
  /// The rewarded ad.
  var rewardedAd: GADRewardedAd?

  override func viewDidLoad() {
  super.viewDidLoad()
  let request = GADRequest()
  GADRewardedAd.load(withAdUnitID: "ca-app-pub-8123415297019784/9501821136",
                          request: request, completionHandler: { (ad, error) in
                            if let error = error {
                              print("Rewarded ad failed to load with error: \(error.localizedDescription)")
                              return
                            }
                            self.rewardedAd = ad
                            self.rewardedAd?.fullScreenContentDelegate = self
                          }
  )
  }
}

Objective-C

@import GoogleMobileAds;
@import UIKit;

@interface ViewController () 

@property(nonatomic, strong) GADRewardedAd *rewardedAd;

@end

@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];

  GADRequest *request = [GADRequest request];
  [GADRewardedAd loadWithAdUnitID:@"ca-app-pub-3940256099942544/1712485313"
                          request:request
                completionHandler:^(GADRewardedAd *ad, NSError *error) {
    if (error) {
      NSLog(@"Rewarded ad failed to load with error: %@", [error localizedDescription]);
      return;
    }
    self.rewardedAd = ad;
    NSLog(@"Rewarded ad loaded.");
    self.rewardedAd.fullScreenContentDelegate = self;
}

広告を表示して報酬を処理する

リワード広告では、ユーザーがリワードを獲得したときにイベントを処理する必要があります。 GADRewardedAd APIのバージョン7では、 GADRewardedAdDelegateプロトコルの一部としてrewardedAd:userDidEarnReward:を実装します。バージョン8では、広告を表示するためにGADUserDidEarnRewardHandlerを実装します。

v7

迅速

func showRewardedAd() {
  ...
  if rewardedAd.isReady {
    rewardedAd.present(fromRootViewController: self delegate:self)
  } else {
    print("Ad wasn't ready")
  }
}

/// Tells the delegate that the user earned a reward.
func rewardedAd(_ rewardedAd: GADRewardedAd, userDidEarnReward: GADAdReward) {
  // TODO: Reward the user.
}

Objective-C

- (void)showRewardedAd: {
  ...
  if (self.rewardedAd.isReady) {
    [self.rewardedAd presentFromRootViewController:self delegate:self];
  } else {
    NSLog(@"Ad wasn't ready");
  }
}

/// Tells the delegate that the user earned a reward.
- (void)rewardedAd:(GADRewardedAd *)rewardedAd userDidEarnReward:(GADAdReward *)reward {
  // TODO: Reward the user.
}

v8

迅速

func showRewardedAd() {
  ...
  if let ad = rewardedAd {
      ad.present(fromRootViewController: self,
               userDidEarnRewardHandler: {
                 let reward = ad.adReward
                 // TODO: Reward the user.
               }
      )
  } else {
    print("Ad wasn't ready")
  }
}

Objective-C

- (void)showRewardedAd: {
  ...
  if (self.rewardedAd) {
    [self.rewardedAd presentFromRootViewController:self
                          userDidEarnRewardHandler:^ {
      GADAdReward *reward = self.rewardedAd.adReward;
      // TODO: Reward the user.
    }];
  } else {
    NSLog(@"Ad wasn't ready");
  }
}

プレゼンテーション広告イベント

GADRewardedAd APIを使用して、広告を表示するメソッドにGADRewardedAdDelegateを渡します。 GADRewardedAd APIを使用すると、広告を表示する前に、 GADFullscreenContentDelegateを広告のプロパティとして設定します。

v7

迅速

func showRewardedAd() {
  ...
  if rewardedAd.isReady {
    rewardedAd.present(fromRootViewController: self delegate:self)
  } else {
    print("Ad wasn't ready")
  }
}

/// Tells the delegate that the rewarded ad was presented.
func rewardedAdDidPresent(_ rewardedAd: GADRewardedAd) {
  print("Rewarded ad presented.")
}
/// Tells the delegate that the rewarded ad was dismissed.
func rewardedAdDidDismiss(_ rewardedAd: GADRewardedAd) {
  print("Rewarded ad dismissed.")
}
/// Tells the delegate that the rewarded ad failed to present.
func rewardedAd(_ rewardedAd: GADRewardedAd, didFailToPresentWithError error: Error) {
  print("Rewarded ad failed to present with error: \(error.localizedDescription).")
}

Objective-C

- (void)showRewardedAd: {
  ...
  if (self.rewardedAd.isReady) {
    [self.rewardedAd presentFromRootViewController:self delegate:self];
  } else {
    NSLog(@"Ad wasn't ready");
  }
}

/// Tells the delegate that the rewarded ad was presented.
- (void)rewardedAdDidPresent:(GADRewardedAd *)rewardedAd {
  NSLog(@"Rewarded ad presented.");
}

/// Tells the delegate that the rewarded ad failed to present.
- (void)rewardedAd:(GADRewardedAd *)rewardedAd didFailToPresentWithError:(NSError *)error {
  NSLog(@"Rewarded ad failed to present with error: %@",
        [error localizedDescription]);
}

/// Tells the delegate that the rewarded ad was dismissed.
- (void)rewardedAdDidDismiss:(GADRewardedAd *)rewardedAd {
  NSLog(@"Rewarded ad dismissed.");
}

v8

迅速

override func viewDidLoad() {
  super.viewDidLoad()
  let request = GADRequest()
  GADRewardedAd.load(withAdUnitID: "ca-app-pub-8123415297019784/9501821136",
                          request: request, completionHandler: { (ad, error) in
                            if let error = error {
                              print(error.localizedDescription)
                              return
                            }
                            self.rewardedAd = ad
                            self.rewardedAd?.fullScreenContentDelegate = self
                          }
  )
}

/// Tells the delegate that the rewarded ad was presented.
func adDidPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) {
  print("Rewarded ad presented.")
}
/// Tells the delegate that the rewarded ad was dismissed.
func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) {
  print("Rewarded ad dismissed.")
}
/// Tells the delegate that the rewarded ad failed to present.
func ad(_ ad: GADFullScreenPresentingAd,
    didFailToPresentFullScreenContentWithError error: Error) {
  print("Rewarded ad failed to present with error: \(error.localizedDescription).")
}

Objective-C

- (void)viewDidLoad {
  [super viewDidLoad];

  GADRequest *request = [GADRequest request];
  [GADRewardedAd loadWithAdUnitID:@"ca-app-pub-3940256099942544/1712485313"
                          request:request
                completionHandler:^(GADRewardedAd *ad, NSError *error) {
    if (error) {
      NSLog(@"Rewarded ad failed to load with error: %@", [error localizedDescription]);
      return;
    }
    self.rewardedAd = ad;
    NSLog(@"Rewarded ad loaded.");
    self.rewardedAd.fullScreenContentDelegate = self;
}

/// Tells the delegate that the rewarded ad was presented.
- (void)adDidPresentFullScreenContent:(id)ad {
  NSLog(@"Rewarded ad presented.");
}

/// Tells the delegate that the rewarded ad failed to present.
- (void)ad:(id)ad
    didFailToPresentFullScreenContentWithError:(NSError *)error {
  NSLog(@"Rewarded ad failed to present with error: %@",
       [error localizedDescription]);
}

/// Tells the delegate that the rewarded ad was dismissed.
- (void)adDidDismissFullScreenContent:(id)ad {
  NSLog(@"Rewarded ad dismissed.");
}

レガシーGADRwardedBasedVideoAdAPIの削除

新しいGADRewardedAdは、2019年3月に最初に導入され、18か月以上にわたって推奨されるリワードAPIです。一度に複数のリワード広告をロードする機能など、従来のGADRewardedBasedVideoAdと比較してより多くの拡張機能があります。

従来のGADRewardedBasedVideoAdは、SDKバージョン8.0.0で削除されました。

アダプティブバナーを支持するスマートバナーの非推奨

スマートバナー広告は廃止され、アダプティブバナー広告が採用されました。アダプティブバナーは、広告幅の設定において優れたパフォーマンスと柔軟性を提供します。次のコードスニペットに示すように、全幅バナーを引き続き使用する場合は、アダプティブバナーを使用して行うことができます。

迅速

class ViewController: UIViewController {

  override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    // Note: The safe area is not known until viewWillAppear.
    let adSize = getFullWidthAdaptiveAdSize()
  }

  func getFullWidthAdaptiveAdSize() -> GADAdSize {
    // Here safe area is taken into account, hence the view frame is used after the
    // view has been laid out.
    let frame = { () -> CGRect in
      if #available(iOS 11.0, *) {
        return view.frame.inset(by: view.safeAreaInsets)
      } else {
        return view.frame
      }
    }()
    return GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(frame.size.width)
  }
}

Objective-C

@implementation ViewController

- (void)viewDidAppear:(BOOL)animated {
  [super viewDidAppear:animated];
  // Note: The safe area is not known until viewWillAppear.
  GADAdSize adSize = [self getFullWidthAdaptiveAdSize];
}

- (GADAdSize)getFullWidthAdaptiveAdSize {
  CGRect frame = self.view.frame;
  // Here safe area is taken into account, hence the view frame is used after
  // the view has been laid out.
  if (@available(iOS 11.0, *)) {
    frame = UIEdgeInsetsInsetRect(self.view.frame, self.view.safeAreaInsets);
  }
  return GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(frame.size.width);
}

@end

アプリケーションのコールバックの削除を残す

すべての広告フォーマットの willLeaveApplication コールバックが削除され、 applicationDidEnterBackground: :メソッドとsceneDidEnterBackground:メソッドが採用されました。 OSレベルのAPIを使用すると、広告の操作によるものかどうかに関係なく、ユーザーがアプリを離れるたびに通知されます。

willLeaveApplication コールバックは、広告クリックハンドラーを意図したものではなく、クリックを報告するためにこのコールバックに依存しても、正確な指標は生成されなかったことに注意してください。たとえば、外部ブラウザを起動したAdChoicesアイコンをクリックすると、コールバックが呼び出されましたが、クリックはカウントされませんでした。

クラスの名前を変更

次の表に、バージョン8で変更または削除された特定のクラス名を示します。

  • GADUnifiedNativeAdに関連するすべてのクラスは、 GADUnifiedNativeAdに名前が変更されGADNativeAdた。
  • GADRewardBasedVideoAdGADNativeExpressAdView 、およびGADInstreamAdは削除されました。
  • DFPプレフィックスを持つすべてのクラスは、 GAMプレフィックスに置き換えられました。
v7.68.0クラスv8.0.0クラス
DFPBannerView GAMBannerView
DFPBannerViewOptions GAMBannerViewOptions
DFPInterstitial GAMInterstitialAd
DFPRequest GAMRequest
GADRequestError NSError
GADUnifiedNativeAdView GADNativeAdView
GADUnifiedNativeAd GADNativeAd
GADUnifiedNativeAdAssetIdentifiers GADNativeAdAssetIdentifiers
GADUnifiedNativeAdDelegate GADNativeAdDelegate
GADUnifiedNativeAdUnconfirmedClickDelegate GADNativeAdUnconfirmedClickDelegate
GADNativeCustomTemplateAd GADCustomNativeAd
GADNativeCustomTemplateAdLoaderDelegate GADCustomNativeAdLoaderDelegate
GADNativeAdDelegate GADCustomNativeAdDelegate
GADInAppPurchase削除
GADInterstitial GADInterstitialAd
GADNativeExpressAdView削除
GADRewardBasedVideoAd削除
GADInstreamAd削除
GADInstreamAdView削除

削除/置換されたメソッド

次の表に、バージョン8での特定の変更を示します。

  • 以前に廃止されたメソッドとプロパティは削除されました。
  • -willLeaveApplication:すべての形式でデリゲートメソッドが削除されました。
  • 広告ネットワークのクラス名がGADResponseInfoプロパティに移動しました。
  • テストデバイス識別子がGADRequestConfigurationプロパティに移動しました。
v7.68.0クラスv7.68.0 API v8.0.0 APIノート
GADMobileAds + configureWithApplicationID: -startWithCompletionHandler:これで、アプリIDがInfo.plistに設定されました。
+ disableAutomatedInApp PurchaseReporting -disableAutomatedInApp PurchaseReporting
+ disableSDKCrashReporting -disableSDKCrashReporting
GADRequest testDevices GADRequestConfiguration .testdeviceidentifiers testDeviceIdentifiersプロパティはすべての広告リクエストに適用されますが、古いtestDevicesプロパティはリクエストごとに設定されていました。
性別削除
誕生日削除
+ sdkVersion GADMobileAds.sharedInstance .sdkVersion
-setBirthday WithMonth:day:year:削除
-setLocationWithDescription: -setLocationWith Latitude:longitude:accuracy:
-tagForChildDirectedTreatment: [GADMobileAds.sharedInstance.requestConfiguration tagForChildDirectedTreatment]
GADErrorCode kGADError * GADError * kプレフィックスは、すべてのエラーコード定数から削除されます。
GADBannerView hasAutoRefreshed autoloadEnabled
inAppPurchaseDelegate削除
MediatedAdView削除
adNetworkClassName responseInfo .adNetworkClassName
DFPBannerView -setValidAdSizesWithSizes: -setValidAdSizes:
DFPBannerViewOptions -adSizeDelegate削除
GADBannerViewDelegate -adViewDidReceiveAd: -bannerViewDidReceiveAd:
-adView:didFailToReceive AdWithError: -bannerView:didFailToReceive AdWithError:
-adViewWillPresentScreen: -bannerViewWillPresentScreen:
-adViewWillDismissScreen: -bannerViewWillDismissScreen:
-adViewDidDismissScreen: -bannerViewDidDismissScreen:
-adViewWillLeaveApplication:削除
GADNativeCustomTemplateAd templateID GADCustomNativeAd.formatID
-performClickOnAssetWithKey:customClickHandler: -performClickOnAssetWithKey:
GADNativeAdImageAd LoaderOptions PreferredImageOrientation GADNativeAdMediaAdOptions .mediaAspectRatio
GADInterstitial inAppPurchaseDelegate削除
isReady削除代わりに、canPresentFrom RootViewController:error:を使用してください。
hasBeenUsed削除
-初期化-initWithAdUnitID:
-setAdUnitID: -initWithAdUnitID:
adNetworkClassName responseInfo .adNetworkClassName
-interstitialWill LeaveApplication:削除
GADUnifiedNativeAd videoController mediaContent.videoController
adNetworkClassName responseInfo .adNetworkClassName