SDK の移行

このページでは、移行にまつわる最新のバージョンと以前のバージョンに関する情報を説明します。

10 から v11 に移行する

Minimum deployment target

The minimum deployment target has been increased to iOS 12.

Minimum Xcode version

The minimum supported Xcode version has been increased to 15.1.

Ads stop serving on iOS 12

Google Mobile Ads SDK version 11.0.0 serves ads only on devices running iOS 13 and higher.

Removed GoogleAppMeasurement dependency

In version 11.0.0, the dependency on GoogleAppMeasurement has been removed. This dependency that powered the user metrics toggle in AdMob will be discontinued in early 2024. To continue collecting user metrics in AdMob, link your AdMob app to Firebase and integrate the Google Analytics for Firebase SDK into your app.

Changes to full-screen ad presentation

The following changes affect the various ad formats:

  • App open
  • Interstitial
  • Rewarded
  • Rewarded interstitial

The view controller parameter in -canPresentFromRootViewController:error: and -presentFromRootViewController: is nullable. If nil is passed, the ad is presented from the topmost view controller in the view controller hierarchy.

Methods removed

The following methods are removed.

v11.0.0 Type Method Notes
GADAppOpenAd load(withAdUnitID adUnitID: String, request: GADRequest?, orientation: UIInterfaceOrientation) Use load(withAdUnitID adUnitID: String, request: GADRequest?) instead.
GADMediationBannerAdEventDelegate willBackgroundApplication() No replacement.
GADMediationInterstitialAdEventDelegate willBackgroundApplication() No replacement.
GADMediationNativeAdEventDelegate willBackgroundApplication() No replacement.
GADMediationRewardedAdEventDelegate didRewardUser(with reward: GADAdReward) Use didRewardUser() instead.
GADMediatedUnifiedNativeAdNotificationSource mediatedNativeAdWillLeaveApplication(_ mediatedNativeAd: GADMediatedUnifiedNativeAd) No replacement.
GADRequestConfiguration setSameAppKeyEnabled(_ enabled: Bool) Use setPublisherFirstPartyIDEnabled(_ enabled: Bool) instead.
tagForUnderAge(ofConsent underAgeOfConsent: Bool) Use the tagForUnderAgeOfConsent property instead.
tag(forChildDirectedTreatment childDirectedTreatment: Bool) Use the tagForChildDirectedTreatment property instead.

Properties removed

The following properties are removed.

v11.0.0 Class Property Notes
GADMediationAdConfiguration hasUserLocation No replacement.
userLatitude
userLongitude
userLocationAccuracyInMeters
childDirectedTreatment Use GADMobileAds.sharedInstance.requestConfiguration.tagForChildDirectedTreatment instead.
GADResponseInfo adNetworkClassName Use adNetworkClassName from loadedAdNetworkResponseInfo instead.

Removed GADAdFormatUnknown

Removed GADAdFormatUnknown with no replacement.

Changes to logging SDK version

Version 11.0.0 removes sdkVersion. To log the Google Mobile Ads SDK version, use versionNumber instead.

Version 10.0.0

GADMobileAds.sharedInstance().sdkVersion

Version 11.0.0

GADGetStringFromVersionNumber(GADMobileAds.sharedInstance().versionNumber)

Changes to GADAdLoader error handling

Starting in version 11.0.0, GADAdLoader doesn't make an ad request if its delegate doesn't conform to the requested ad types' delegate protocol. Previously, it failed after the ad request was made.

Changes to testing behavior

See the table which shows the updated conditions for when the following properties return true.

Class Property
GADMediationAdConfiguration isTestRequest
GADCustomEventRequest isTesting
v10.0.0 v11.0.0
  • The device is explicitly declared as a test device in testDeviceIdentifiers.
  • The device is explicitly declared as a test device in testDeviceIdentifiers.
  • The device is a simulator.
  • The device is explicitly declared as a test device in the Ad Manager UI.

v9 から v10 に移行する

Ads stop serving on iOS 11

Google Mobile Ads SDK version 10.0.0 serves ads only on devices running iOS 12 and higher.

Upgrading to Google Mobile Ads SDK version 10.0.0 will not break your app on iOS 11 and iOS 10 devices, however, no ads will be served on those devices.

Requirement of Ad Manager App ID

The Ad Manager App ID is now required in Info.plist for all Ad Manager apps and requires the ca-app-pub-################~########## format. See Update your Info.plist for more details.

Requirement of GoogleAppMeasurement.xcframework

GoogleAppMeasurement.xcframework is now required for all Ad Manager apps. If you install the Google Mobile Ads SDK through Cocoapods or Swift Package Manager, no additional action is required. If you install frameworks manually, see Manual Download for more details.

Building with bitcode is no longer supported

Disabling bitcode in your mobile apps is now required to integrate the Google Mobile Ads SDK.

Types removed

Type Notes
GADGender No replacement.
GADMRewardBasedVideoAdNetworkAdapterProtocol All rewarded mediation adapters listed on Choose Networks have stopped using these protocols for over a year. Use GADMediationAdapter for mediation and custom events.
GADMRewardBasedVideoAdNetworkConnectorProtocol

Properties removed

The following properties are removed with no replacement.

v10.0.0 Class Property
GADMediationAdRequest userBirthday
userGender
userHasLocation
userLatitude
userLongitude
userLocationAccuracyInMeters
userLocationDescription
GADCustomEventRequest userHasLocation
userLatitude
userLongitude
userLocationAccuracyInMeters
userLocationDescription

v8 から v9 に移行する

Ads stop serving on iOS 10

The minimum iOS version the Google Mobile Ads SDK version 9.0.0 supports is iOS 11.

Upgrading to Google Mobile Ads SDK version 9.0.0 will not break your app on iOS 10 devices, however, no ads will be served on those devices.

Stricter enforcement of status bar controls

Starting from version 9.0.0, when you present full-screen format ads, your app should ensure that the ads are able to control the presentation of the status bar. You will see an error message in the logs if you fail to do so.

Depending on the specific layout of view controllers in your app, you might not need to make any changes to ensure this. Consider whether you need to set the childViewControllerForStatusBarHidden property on your ad's rootViewController.

Rename adDidPresentFullScreenContent: to adWillPresentFullScreenContent:

There is no behavior change. The delegate method is invoked right before the ad is about to be presented, so the new method name better reflects its functionality.

Remove location setting API on GADRequest

- (void)setLocationWithLatitude:longitude:accuracy: has been deleted from GADRequest since location data is not used by Google to target ads. Use third-party APIs to provide the information to third-party ad networks if required.

Custom event interfaces deprecation

Custom events enable publishers using Ad Manager Mediation to add waterfall mediation for an ad network that isn't one of the supported ad networks.

All the custom event protocols are deprecated. Instead, use the existing GADMediationAdapter and GADMediationAdEventDelegate protocols to achieve the same functionalities. This change improves clarity and enables you to create custom events for rewarded ads and interscroller ads which were not previously available.

APIs

The table below lists the corresponding mediation adapter APIs to custom events APIs that should be used starting from version 9.0.0.

v8 v9
GADCustomEventBanner
GADCustomEventInterstitial
GADCustomEventNativeAd
GADMediationAdapter GADMediationBannerAd
GADMediationInterstitialAd
GADMediationInterscrollerAd
GADMediationRewardedAd
GADMediationNativeAd
delegate Delegate is returned by the load completion handler of each load function of GADMediationAdapter class
-init -init
-requestBannerAd:parameter:label:request: -loadBannerForAdConfiguration:completionHandler:
-requestInterstitialAdWithParameter:label:request: -loadInterstitialForAdConfiguration:completionHandler:
-requestNativeAdWithParameter:request:adTypes:options:rootViewController: -loadNativeAdForAdConfiguration:completionHandler:
N/A -loadInterscrollerAdForAdConfiguration:completionHandler:
N/A -loadRewardedAdForAdConfiguration:completionHandler:
-presentFromRootViewController: -presentFromViewController:
-handlesUserClicks -handlesUserClicks
-handlesUserImpressions -handlesUserImpressions

Delegate methods

The table below lists the corresponding mediation ad event delegate methods to custom event delegate methods that should be used starting from version 9.0.0.

v8 v9
GADCustomEventBannerDelegate
GADCustomEventInterstitialDelegate
GADCustomEventNativeAdDelegate
GADMediationAdEventDelegate GADMediationAd
-customEventBanner:didReceiveAd:
-customEventInterstitialDidReceiveAd:
Ad load status is included in the load completion handler of each load function in the GADMediationAdapter class
-customEventBanner:didFailAd:
-customEventInterstitial:didFailAd:
-customEventBannerWasClicked:
-customEventInterstitialWasClicked:
-reportClick
-customEventBannerWillPresentModal:
-customEventInterstitialWillPresentModal:
-willPresentFullScreenView
-customEventBannerWillDismissModal:
-customEventInterstitialWillDismissModal:
-willDismissFullScreenView
-customEventBannerDidDismissModal:
-customEventInterstitialDidDismissModal:
-didDismissFullScreenView
-customEventBannerWillLeaveApplication:
-customEventInterstitialWillLeaveApplication:
-willBackgroundApplication
viewControllerForPresentingModalView -[GADMediationBannerAd view]

Other removed/replaced methods and constants

Changes to method, constant, or property
kGAD- prefixed constants Removed. Use GAD- prefixed constants.
GADAdNetworkResponseInfo credentials were removed. Use adUnitMapping instead.
GAMRequest kGAMSimulatorID in GAMRequest is deprecated. Use GADSimulatorID in GADRequestConfiguration instead.
GADCustomNativeAd mediaView in GADCustomNativeAd is deprecated. Use mediaContent instead.
In-App Purchase APIs in GoogleMobileAds inAppPurchase APIs in GoogleMobileAds were removed.

v7 から v8 に移行する

Google Mobile Ads SDK バージョン 8.0.0 では、いくつかの大きな変更に加え、 API の名前変更と削除が行われます。

全画面形式の API の更新

バージョン 8.0.0 以降、インタースティシャル広告とリワード広告では、 一貫性を持たせましょうこれらの新しいフルスクリーン広告 API では バージョン 7 のフルスクリーン広告 API との主な違いは次のとおりです。

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

    フルスクリーン広告の読み込みと表示に関する従来のアプローチは次のようになります。

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

    バージョン 8 ではアプローチが若干変更されています。読み込みコールバックは 委任することもできます。代わりに、load メソッドに 完了ハンドラ:

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

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

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

    イベントの種類 既存の API バージョン 8 API
    読み込みイベント GADInterstitialDelegate または GADRewardedAdDelegate GAMInterstitialAdLoadCompletionHandler または GADRewardedAdLoadCompletionHandler
    プレゼンテーション イベント GADFullScreenContentDelegate

    以前は、広告イベントをリッスンするために、 実装する GADInterstitialDelegate インタースティシャルのデリゲート プロパティにプロトコルを渡すか、 実装する GADRewardedAdDelegate フォーマットに応じて、リワード広告のデリゲート プロパティにプロトコルを 確認できます。このデリゲートには、読み込みと処理の両方に関連するメソッドがあり、 ライフサイクルなどがあります。

    バージョン 8 では、読み込みイベントと表示イベントが分離されています。今すぐ 登録して GADFullScreenContentDelegate 広告を表示する前であればいつでも、1 つの広告ユニットを 1 つ設定 デリゲートする方法もあります。広告掲載イベントは 読み込みメソッドで渡される単一の読み込み完了ハンドラに移動します。

インタースティシャル

広告を読み込む

以下のコード スニペットは、インタースティシャル広告を読み込んで イベントをリッスンします。

v7

Swift

import GoogleMobileAds
import UIKit

class ViewController: UIViewController, GADInterstitialDelegate {

  var interstitial: DFPInterstitial!

  override func viewDidLoad() {
    super.viewDidLoad()
    interstitial = DFPInterstitial(adUnitID: "/21775744923/example/interstitial")
    interstitial.delegate = self
    let request = GAMRequest()
    interstitial.load(request)
  }

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

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

Objective-C

@import GoogleMobileAds;
@import UIKit;

@interface ViewController () 

@property(nonatomic, strong) DFPInterstitial *interstitial;

@end

@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];
  self.interstitial = [[DFPInterstitial alloc]
      initWithAdUnitID:@"/21775744923/example/interstitial"];
  self.interstitial.delegate = self;
  GAMRequest *request = [GAMRequest request];
  [self.interstitial loadRequest:request];
}

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

/// Tells the delegate an ad request failed.
- (void)interstitial:(DFPInterstitial *)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: GAMInterstitialAd?

  override func viewDidLoad() {
    super.viewDidLoad()
    let request = GAMRequest()
    GAMInterstitialAd.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) GAMInterstitialAd *interstitial;

@end

@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];
  GAMRequest *request = [GAMRequest request];
  [GAMInterstitialAd loadWithAdUnitID:@"/21775744923/example/interstitial"
                              request:request
                    completionHandler:^(GAMInterstitialAd *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 = DFPInterstitial(adUnitID: "/21775744923/example/interstitial")
  interstitial.delegate = self
  ...
}

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

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

/// Tells the delegate the interstitial had been animated off the screen.
func interstitialDidDismissScreen(_ ad: DFPInterstitial) {
  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: DFPInterstitial) {
  print("Interstitial ad will leave application.")
}

Objective-C

- (void)viewDidLoad {
  [super viewDidLoad];
  self.interstitial = [[DFPInterstitial alloc] initWithAdUnitID:"/21775744923/example/interstitial"];
  self.interstitial.delegate = self;
  ...
}

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

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

/// Tells the delegate the interstitial had been animated off the screen.
- (void)interstitialDidDismissScreen:(DFPInterstitial *)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:(DFPInterstitial *)ad {
  NSLog(@"Interstitial ad will leave application.");
}

v8

Swift

override func viewDidLoad() {
  super.viewDidLoad()
  let request = GAMRequest()
  GAMInterstitialAd.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];
  GAMRequest *request = [GAMRequest request];
  [GAMInterstitialAd loadWithAdUnitID:@"/21775744923/example/interstitial"
                              request:request
                    completionHandler:^(GAMInterstitialAd *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(GAMRequest()) { 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;
  GAMRequest *request = [GAMRequest 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 = GAMRequest()
  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];

  GAMRequest *request = [GAMRequest 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;
}

ディスプレイ広告と報酬の処理

リワード広告では、ユーザーが報酬を獲得したときにイベントを処理する必要があります。あり バージョン 7 の GADRewardedAd API を使用する場合は、 GADRewardedAdDelegate プロトコルの一部としての rewardedAd:userDidEarnReward:。 バージョン 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 = GAMRequest()
  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];

  GAMRequest *request = [GAMRequest 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.");
}

従来の GAD リワード広告 BasedVideoAd API の削除

新しい GADRewardedAd API は 2019 年 3 月に初めて導入され、 使用してきました従来版よりも機能が強化されたため、 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

アプリからのコールバックの削除

すべての広告フォーマットの willLeaveApplication コールバックは、 廃止され、 applicationDidEnterBackground: および sceneDidEnterBackground: あります。OS レベルの API を使用すると、ユーザーがアプリを離れるたびに、 広告インタラクションに起因するものか否かを 把握できます

なお、 willLeaveApplication コールバックは、 このコールバックを使用してクリックをレポートしても、 正確な指標が生成されます。たとえば AdChoices ボタンがクリックされ、 アイコンが、外部ブラウザを起動したためにコールバックを呼び出したものの、 。

クラス名の変更

以下の表は、 バージョン 8.概要は次のとおりです。

  • GADUnifiedNativeAd に関連するすべてのクラスの名前が次のように変更されました: GADNativeAd
  • GADRewardBasedVideoAd さん、GADNativeExpressAdView さん、GADInstreamAd さん、 削除されました。
  • DFP 接頭辞を持つすべてのクラスが、GAM 接頭辞に置き換えられました。
v7.68.0 クラス v8.0.0 クラス
DFPBannerView GAMBannerView
DFPBannerViewOptions GAMBannerViewOptions
DFPInterstitial GAMInterstitialAd
DFPRequest GAMRequest
GADRequestError NSError
GADUnifiedNativeAdView GADNativeAdView
GADUnifiedGAD GADNativeAd
GADUnifiedNativeAdAssetIdentifiers GADNativeAdAssetIdentifiers
GADUnifiedNativeAdDelegate GADNativeAdDelegate
GADUnifiedNativeAdUnconfirmedClickDelegate GADNativeAdUnconfirmedClickDelegate
GADNativeCustomTemplateAd GADCustomNativeAd
GADNativeCustomTemplateAdLoaderDelegate GADCustomNativeAdLoaderDelegate
GADNativeAdDelegate GADCustomNativeAdDelegate
GADInAppPurchase 削除済み
GADInterstitial GADInterstitialAd
GADNativeExpressAdView 削除済み
GADRewardBasedVideoAd 削除済み
GADInstreamAd 削除済み
GADInstreamAdView 削除済み

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

バージョン 8 の具体的な変更点は下表のとおりです。概要は次のとおりです。

  • 以前にサポートが終了したメソッドとプロパティが削除されました。
  • すべてのフォーマットで -willLeaveApplication: デリゲート メソッドを削除しました。
  • 広告ネットワークのクラス名は GADResponseInfo プロパティに移動しました。
  • テストデバイス ID は GADRequestConfiguration に移動しました プロパティです。
v7.68.0 クラス v7.68.0 API バージョン 8.0.0 API メモ
GADMobileAds +configureWithApplicationID: -startWithCompletionHandler: これで、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: -bannerViewDidReceiveAd:
-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 -initWithAdUnitID:
-setAdUnitID: -initWithAdUnitID:
adNetworkClassName responseInfo.adNetworkClassName
-interstitialWillLeaveApplication: 削除済み
GADUnifiedGAD videoController mediaContent.videoController
adNetworkClassName responseInfo.adNetworkClassName