1. スマートバナーからアダプティブバナー
(1) バナーサイズ
kGADAdSizeSmartBannerPortrait → GADPortraitAnchoredAdaptiveBannerAdSizeWithWidth(self.view.frame.size.width)
kGADAdSizeSmartBannerLandscape → GADLandscapeAnchoredAdaptiveBannerAdSizeWithWidth(self.view.frame.size.width)
(2) エラー受信処理
変更前
- (void)adView:(GADBannerView *)view didFailToReceiveAdWithError:(GADRequestError *)error
変更後
- (void)bannerView:(nonnull GADBannerView *)bannerView didFailToReceiveAdWithError:(nonnull NSError *)error
2. インターステイシャル広告からフルスクリーン広告への移行
(1) .hファイル
#import <GoogleMobileAds/GADInterstitialDelegate.h > → 削除
GADInterstitialDelegate → GADFullScreenContentDelegate
GADInterstitial → GADInterstitialAd
(2) .mファイル
A. 広告ロード処理
変更前
- (void)interstitialLoad {
// AdMobインタースティシャルのロード
interstitial_ = [[GADInterstitial alloc] initWithAdUnitID:@"ca-app-pub-XXXX"];
interstitial_.delegate = self;
if ([NSThread isMainThread]) { // メインスレッドで実行されているか
// Initiate a generic request to load it with an ad.
[interstitial_ loadRequest:[GADRequest request]];
} else { // メインスレッドで実行されていない
dispatch_async(dispatch_get_main_queue(), ^{ // メインスレッドで実行する
// Initiate a generic request to load it with an ad.
[self->interstitial_ loadRequest:[GADRequest request]];
});
}
}
変更後
- (void)interstitialLoad {
// AdMobインタースティシャルのロード
if ([NSThread isMainThread]) { // メインスレッドで実行されているか
[self interstitialLoadSub];
} else { // メインスレッドで実行されていない
dispatch_async(dispatch_get_main_queue(), ^{ // メインスレッドで実行する
[self interstitialLoadSub];
});
}
}
- (void)interstitialLoadSub {
// Initiate a generic request to load it with an ad.
GADRequest *request = [GADRequest request];
[GADInterstitialAd loadWithAdUnitID:@"ca-app-pub-XXXX"
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;
}];
}
B. 広告が閉じられた場合の処理(変更後のコードは、エラー処理も記載)
変更前
- (void)interstitialDidDismissScreen:(GADInterstitial *)interstitial {
// AdMobインタースティシャルが閉じられると呼ばれる
[self interstitialLoad];
}
変更後
/// Tells the delegate that the ad failed to present full screen content.
- (void)ad:(nonnull id)ad didFailToPresentFullScreenContentWithError:(nonnull NSError *)error {
NSLog(@"Ad did fail to present full screen content.");
}
/// Tells the delegate that the ad presented full screen content.
- (void)adDidPresentFullScreenContent:(nonnull id)ad {
NSLog(@"Ad did present full screen content.");
}
/// Tells the delegate that the ad dismissed full screen content.
- (void)adDidDismissFullScreenContent:(nonnull id)ad {
// AdMobインタースティシャルが閉じられると呼ばれる
NSLog(@"Ad did dismiss full screen content.");
[self interstitialLoad];
}
C. 広告表示処理
変更前
// AdMobインタースティシャル広告の表示
if ([self->interstitial_ isReady]) {
[self->interstitial_ presentFromRootViewController:self];
}
変更後
// AdMobインタースティシャル広告の表示
if (self->interstitial_) {
[self->interstitial_ presentFromRootViewController:self];
}
参考記事:
https://developers.google.com/admob/ios/interstitial
https://developers.google.com/admob/ios/banner/adaptive?hl=ja
https://developers.google.com/admob/ios/api/reference/Functions
https://developers.google.com/ad-manager/mobile-ads-sdk/ios/api/reference/Functions
https://developers.google.com/admob/ios/test-ads?hl=ja