SDK の移行

このページでは、iOS 向け Google Mobile Ads SDK の最新バージョンと以前のバージョンへの移行について説明します。バージョン 11.0.0 は 2024 年 1 月にリリースされる予定です。

SDK バージョン v10 から v11 に移行する

最小デプロイ ターゲット

最小デプロイ ターゲットが iOS 12 に引き上げられました。

Xcode の最小バージョン

サポートされる Xcode の最小バージョンが 15.1 に引き上げられました。

iOS 12 での広告配信が停止されます

Google Mobile Ads SDK バージョン 11.0.0 では、iOS 13 以降を搭載したデバイスにのみ広告が配信されます。

GoogleAppMeasurement の依存関係を削除しました

バージョン 11.0.0 では、GoogleAppMeasurement に対する依存関係が削除されました。AdMob でユーザーに関する指標の切り替えに使用されていたこの依存関係は、2024 年初頭に廃止される予定です。AdMob でユーザーに関する指標を引き続き収集するには、AdMob アプリを Firebase にリンクし、Firebase 向け Google アナリティクス SDK をアプリに統合します。

全画面広告の表示に関する変更

各広告フォーマットに影響する変更点は次のとおりです。

  • アプリ起動
  • インタースティシャル
  • 特典
  • リワード インタースティシャル

-canPresentFromRootViewController:error:-presentFromRootViewController: のビュー コントローラ パラメータは null を許容します。nil が渡されると、広告はビュー コントローラ階層の最上位のビュー コントローラから表示されます。

削除されたメソッド

次のメソッドは削除されます。

v11.0.0 タイプ メソッド メモ
GADAppOpenAd load(withAdUnitID adUnitID: String, request: GADRequest?, orientation: UIInterfaceOrientation) 代わりに load(withAdUnitID adUnitID: String, request: GADRequest?) を使用してください。
GADMediationBannerAdEventDelegate willBackgroundApplication() 代替はありません。
GADMediationInterstitialAdEventDelegate willBackgroundApplication() 代替はありません。
GADMediationNativeAdEventDelegate willBackgroundApplication() 代替はありません。
GADMediationRewardedAdEventDelegate didRewardUser(with reward: GADAdReward) 代わりに didRewardUser() を使用してください。
GADMediatedUnifiedNativeAdNotificationSource mediatedNativeAdWillLeaveApplication(_ mediatedNativeAd: GADMediatedUnifiedNativeAd) 代替はありません。
GADRequestConfiguration setSameAppKeyEnabled(_ enabled: Bool) setPublisherFirstPartyIDEnabled(_ enabled: Bool) を代わりに使用してください。
tagForUnderAge(ofConsent underAgeOfConsent: Bool) 代わりに tagForUnderAgeOfConsent プロパティを使用してください。
tag(forChildDirectedTreatment childDirectedTreatment: Bool) 代わりに tagForChildDirectedTreatment プロパティを使用してください。

削除されたプロパティ

次のプロパティが削除されます。

v11.0.0 クラス プロパティ メモ
GADMediationAdConfiguration hasUserLocation 代替はありません。
userLatitude
userLongitude
userLocationAccuracyInMeters
childDirectedTreatment 代わりに GADMobileAds.sharedInstance.requestConfiguration.tagForChildDirectedTreatment を使用してください。
GADResponseInfo adNetworkClassName 代わりに loadedAdNetworkResponseInfoadNetworkClassName を使用してください。

GADAdFormatUnknown を削除しました

GADAdFormatUnknown を削除しました(代替はありません)。

Logging SDK バージョンの変更

バージョン 11.0.0 では sdkVersion が削除されました。Google Mobile Ads SDK のバージョンを記録するには、代わりに versionNumber を使用します。

バージョン 10.0.0

GADMobileAds.sharedInstance().sdkVersion

バージョン 11.0.0

GADGetStringFromVersionNumber(GADMobileAds.sharedInstance().versionNumber)

GADAdLoader のエラー処理の変更

バージョン 11.0.0 以降では、GADAdLoaderdelegate がリクエストされた広告タイプのデリゲート プロトコルに準拠していない場合、広告リクエストは行いません。以前は、広告リクエストの送信後に失敗していました。

テスト動作の変更

次のプロパティが true を返す場合の最新の条件については、次の表をご覧ください。

クラス プロパティ
GADMediationAdConfiguration isTestRequest
GADCustomEventRequest isTesting
v10.0.0 v11.0.0
  • デバイスが testDeviceIdentifiers でテストデバイスとして明示的に宣言されている。
  • デバイスが testDeviceIdentifiers でテストデバイスとして明示的に宣言されている。
  • デバイスがシミュレータである。
  • UI でデバイスがテストデバイスとして明示的に宣言されている。 AdMob

v9 から v10 に移行する

iOS 11 での広告配信が停止されます

Google Mobile Ads SDK バージョン 10.0.0 では、iOS 12 以降を搭載したデバイスにのみ広告が配信されます。

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

ビットコードによるビルドのサポートが終了しました

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

削除された型

種類 メモ
GADGender 代替はありません。
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 以降では、全画面フォーマットの広告を表示する場合、その広告でステータスバーの表示を制御できるようにする必要があります。それができていない場合は、ログにエラー メッセージが表示されます。

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

ad DidPresentFullScreenContent: の名前を adWillPresentFullScreenContent に変更します。

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

GADRequest の Location Settings API を削除

Google は位置情報を広告のターゲティングに使用しないため、- (void)setLocationWithLatitude:longitude:accuracy:GADRequest から削除されました。必要に応じて、第三者 API を使用して第三者広告ネットワークに情報を提供します。

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

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

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

API

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

v8 v9
GADCustomEventBanner
GADCustomEvent インタースティシャル
GADCustomEventNativeAd
GADMediationAdapter GADMediationBannerAd
GADMediation インタースティシャル Ad
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 以降で使用される、カスタム イベント デリゲート メソッドに対応するメディエーション広告イベント デリゲート メソッドの一覧です。

v8 v9
GADCustomEventBannerDelegate
GADCustomEvent インタースティシャル Delegate
GADCustomEventNativeAdDelegate
GADMediationAdEventDelegate GADMediationAd
-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. 表示のコールバックを処理するデリゲートを割り当てます。
    4. 広告を表示する。

    新しいアプローチには次のメリットがあります。

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

    イベントタイプ 既存の API V8 API
    読み込みイベント GADInterstitialDelegate または GADRewardedAdDelegate GADInterstitialAdLoadCompletionHandler または GADRewardedAdLoadCompletionHandler
    プレゼンテーション イベント GADFullScreenContentDelegate

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

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

インタースティシャル

広告を読み込む

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

v7

Swift

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

Swift

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

Swift

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

Swift

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

Swift

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

Swift

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

Swift

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

Swift

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 では、rewardedAd:userDidEarnReward:GADRewardedAdDelegate プロトコルの一部として実装しています。バージョン 8 の場合、広告を表示するためには GADUserDidEarnRewardHandler を実装します。

v7

Swift

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

Swift

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

Swift

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

Swift

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

従来の GADRewardedBasedVideoAd API の削除

新しい GADRewardedAd API は 2019 年 3 月に初めて導入され、18 か月以上にわたり推奨 API となっています。一度に複数のリワード広告を読み込む機能など、従来の GADRewardedBasedVideoAd API よりも機能が充実しています。

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

スマートバナーのサポート終了からアダプティブ バナーへの移行

スマートバナー広告のサポートは終了し、アダプティブ バナー広告に移行しました。アダプティブ バナーはパフォーマンスに優れ、広告の幅を柔軟に設定できます。引き続き全幅バナーを使用する場合は、次のコード スニペットに示すようにアダプティブ バナーを使用してください。

Swift

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

アプリ終了コールバックの削除

applicationDidEnterBackground: メソッドと sceneDidEnterBackground: メソッドに置き換えられたため、すべての広告フォーマットの willLeaveApplication コールバックが削除されました。OS レベルの API を使用すると、広告のインタラクションが原因かどうかにかかわらず、ユーザーがアプリを離れるたびに通知が届きます。

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

クラス名の変更

次の表に、バージョン 8 で変更または削除された具体的なクラス名を示します。手順は次のとおりです。

  • GADUnifiedNativeAd に関連するすべてのクラスの名前が GADNativeAd に変更されました。
  • GADRewardBasedVideoAdGADNativeExpressAdViewGADInstreamAd を削除しました。
  • DFP 接頭辞が付いたクラスはすべて、GAM 接頭辞に置き換えられました。
v7.68.0 クラス v8.0.0 クラス
DFPBannerView GAMBannerView
DFPBannerViewOptions GAMBannerViewOptions
DFPInterstitial GAM インタースティシャル広告
DFPRequest GAMRequest
GADRequestError NSError
GADUnifiedNativeAdView GADNativeAdView
GADUnifiedNativeAd GADNativeAd
GADUnifiedNativeAdAssetIdentifiers GADNativeAdAssetIdentifiers
GADUnifiedNativeAdDelegate GADNativeAdDelegate
GADUnifiedNativeAdUnconfirmedClickDelegate GADNativeAdUnconfirmedClickDelegate
GADNativeCustomTemplateAd GADCustomNativeAd
GADNativeCustomTemplateAdLoaderDelegate GADCustomNativeAdLoaderDelegate
GADNativeAdDelegate GADCustomNativeAdDelegate
GADInAppPurchase 削除
GADInterstitial GAD インタースティシャル広告
GADNativeExpressAdView 削除
GADRewardBasedVideoAd 削除
GADInstreamAd 削除
GADInstreamAdView 削除

削除または置換されたメソッド

以下の表に、バージョン 8 の具体的な変更点を示します。手順は次のとおりです。

  • 以前に非推奨になったメソッドとプロパティが削除されました。
  • -willLeaveApplication: デリゲート メソッドがすべての形式から削除されました。
  • 広告ネットワーク クラス名が GADResponseInfo プロパティに移動しました。
  • テストデバイス ID は GADRequestConfiguration プロパティに移動しました。
v7.68.0 クラス API v7.68.0 API v8.0.0 メモ
GADMobileAds +configureWithApplicationID: -startWithCompleteHandler: これで、Info.plist にアプリ ID が設定されました。
+disableAutomatedInAppPurchaseReporting -disableAutomatedInAppPurchaseReporting
+disableSDKCrashReporting -disableSDKCrashReporting
GADRequest testDevices GADRequestConfiguration.testdeviceidentifiers testDeviceIdentifiers プロパティはすべての広告リクエストに適用されますが、古い testDevices プロパティはリクエストごとに設定されていました。
性別 削除
生年月日 削除
+sdkVersion GADMobileAds.sharedInstance.sdkVersion
-setBirthdayWithMonth:day:year: 削除
-setLocationWithDescription: -setLocationWithLatitude: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: -bannerViewVASTReceiveAd:
-adView:didFailToReceiveAdWithError: -bannerView:didFailToReceiveAdWithError:
-adViewWillPresentScreen: -bannerViewWillPresentScreen:
-adViewWillDismissScreen: -bannerViewWillDismissScreen:
-adViewDidDismissScreen: -bannerViewDidDismissScreen:
-adViewWillLeaveApplication: 削除
GADNativeCustomTemplateAd templateID GADCustomNativeAd.formatID
-performClickOnAssetWithKey:customClickHandler: -performClickOnAssetWithKey:
GADNativeAdImageAdLoaderOptions preferredImageOrientation GADNativeAdMediaAdOptions.mediaAspectRatio
GADInterstitial inAppPurchaseDelegate 削除
isReady 削除 代わりに canPresentFromRootViewController:error: を使用してください。
hasBeenUsed 削除
-init -initWithcategoryID:
-setcategoryID: -initWithcategoryID:
adNetworkClassName responseInfo.adNetworkClassName
-interstitialWillLeaveApplication: 削除
GADUnifiedNativeAd videoController mediaContent.videoController
adNetworkClassName responseInfo.adNetworkClassName