Skip to content

Commit 59c7b70

Browse files
Nicholas Ventimigliacopybara-github
authored andcommitted
Updated Banner to use the Large Anchored Adaptive AdSize.
PiperOrigin-RevId: 861347397
1 parent f5d131e commit 59c7b70

File tree

7 files changed

+150
-8
lines changed

7 files changed

+150
-8
lines changed

Objective-C/admanager/AdManagerBannerExample/AdManagerBannerExample/ViewController.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ - (void)loadBannerAd {
132132
// The returned ad will be centered in the ad view.
133133

134134
// [START ad_size]
135-
// Request an anchored adaptive banner with a width of 375.
136-
self.bannerView.adSize = GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(375);
135+
// Request a large anchored adaptive banner with a width of 375.
136+
self.bannerView.adSize = GADLargeAnchoredAdaptiveBannerAdSizeWithWidth(this, 375);
137137
// [END ad_size]
138138

139139
// [START load_ad]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#import <Foundation/Foundation.h>
2+
#import <GoogleMobileAds/GoogleMobileAds.h>
3+
#import <UIKit/UIKit.h>
4+
5+
NS_ASSUME_NONNULL_BEGIN
6+
7+
@interface BannerSnippets : NSObject <GADBannerViewDelegate>
8+
9+
- (void)createCustomAdSizeWithBannerView:(GADBannerView *)bannerView;
10+
11+
- (void)createAdViewWithAdViewContainer:(UIView *)adViewContainer
12+
rootViewController:(UIViewController *)rootViewController;
13+
14+
- (void)loadBannerAdWithBannerView:(GADBannerView *)bannerView;
15+
16+
@end
17+
18+
NS_ASSUME_NONNULL_END
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#import "BannerSnippets.h"
2+
3+
@implementation BannerSnippets
4+
5+
static NSString *const TestAdUnit = @"ca-app-pub-3940256099942544/2435281174";
6+
7+
- (void)createCustomAdSizeWithBannerView:(GADBannerView *)bannerView {
8+
// [START create_custom_ad_size]
9+
bannerView.adSize = GADAdSizeFromCGSize(CGSizeMake(250, 250));
10+
// [END create_custom_ad_size]
11+
}
12+
13+
// [START create_ad_view]
14+
- (void)createAdViewWithAdViewContainer:(UIView *)adViewContainer
15+
rootViewController:(UIViewController *)rootViewController {
16+
GADBannerView *bannerView = [[GADBannerView alloc] initWithAdSize:GADAdSizeBanner];
17+
bannerView.adUnitID = TestAdUnit;
18+
bannerView.rootViewController = rootViewController;
19+
[adViewContainer addSubview:bannerView];
20+
}
21+
// [END create_ad_view]
22+
23+
// [START load_ad]
24+
- (void)loadBannerAdWithBannerView:(GADBannerView *)bannerView {
25+
// Request a large anchored adaptive banner with a width of 375.
26+
bannerView.adSize = GADLargeAnchoredAdaptiveBannerAdSizeWithWidth(this, 375);
27+
[bannerView loadRequest:[GADRequest request]];
28+
}
29+
// [END load_ad]
30+
31+
// [START ad_events]
32+
#pragma mark - GADBannerViewDelegate
33+
34+
- (void)bannerViewDidReceiveAd:(GADBannerView *)bannerView {
35+
NSLog(@"Banner ad loaded.");
36+
}
37+
38+
- (void)bannerView:(GADBannerView *)bannerView didFailToReceiveAdWithError:(NSError *)error {
39+
NSLog(@"Banner ad failed to load: %@", error.localizedDescription);
40+
}
41+
42+
- (void)bannerViewDidRecordImpression:(GADBannerView *)bannerView {
43+
NSLog(@"Banner ad recorded an impression.");
44+
}
45+
46+
- (void)bannerViewDidRecordClick:(GADBannerView *)bannerView {
47+
NSLog(@"Banner ad recorded a click.");
48+
}
49+
50+
- (void)bannerViewWillPresentScreen:(GADBannerView *)bannerView {
51+
NSLog(@"Banner ad will present screen.");
52+
}
53+
54+
- (void)bannerViewWillDismissScreen:(GADBannerView *)bannerView {
55+
NSLog(@"Banner ad will dismiss screen.");
56+
}
57+
58+
- (void)bannerViewDidDismissScreen:(GADBannerView *)bannerView {
59+
NSLog(@"Banner ad did dismiss screen.");
60+
}
61+
// [END ad_events]
62+
63+
@end

Objective-C/admob/BannerExample/BannerExample/ViewController.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ - (void)startGoogleMobileAdsSDK {
128128

129129
- (void)loadBannerAd {
130130
// [START ad_size]
131-
// Request an anchored adaptive banner with a width of 375.
132-
self.bannerView.adSize = GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(375);
131+
// Request a large anchored adaptive banner with a width of 375.
132+
self.bannerView.adSize = GADLargeAnchoredAdaptiveBannerAdSizeWithWidth(this, 375);
133133
// [END ad_size]
134134

135135
// [START load_ad]

Swift/admanager/AdManagerBannerExample/AdManagerBannerExample/ViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ class ViewController: UIViewController, BannerViewDelegate {
112112
// The returned ad will be centered in the ad view.
113113

114114
// [START ad_size]
115-
// Request an anchored adaptive banner with a width of 375.
116-
bannerView.adSize = currentOrientationAnchoredAdaptiveBanner(width: 375)
115+
// Request a large anchored adaptive banner with a width of 375.
116+
bannerView.adSize = largeAnchoredAdaptiveBanner(width: 375)
117117
// [END ad_size]
118118

119119
// [START load_ad]
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import GoogleMobileAds
2+
import UIKit
3+
4+
class BannerSnippets: NSObject, GADBannerViewDelegate {
5+
6+
let testAdUnit = "ca-app-pub-3940256099942544/2435281174"
7+
8+
func createCustomAdSize(bannerView: GADBannerView) {
9+
// [START create_custom_ad_size]
10+
bannerView.adSize = GADAdSizeFromCGSize(CGSize(width: 250, height: 250))
11+
// [END create_custom_ad_size]
12+
}
13+
14+
// [START create_ad_view]
15+
func createAdView(adViewContainer: UIView, rootViewController: UIViewController) {
16+
let bannerView = GADBannerView(adSize: GADAdSizeBanner)
17+
bannerView.adUnitID = testAdUnit
18+
bannerView.rootViewController = rootViewController
19+
adViewContainer.addSubview(bannerView)
20+
}
21+
// [END create_ad_view]
22+
23+
// [START load_ad]
24+
func loadBannerAd(bannerView: GADBannerView) {
25+
// Request a large anchored adaptive banner with a width of 375.
26+
bannerView.adSize = largeAnchoredAdaptiveBanner(width: 375)
27+
bannerView.load(GADRequest())
28+
}
29+
// [END load_ad]
30+
31+
// [START ad_events]
32+
// MARK: - GADBannerViewDelegate methods
33+
func bannerViewDidReceiveAd(_ bannerView: GADBannerView) {
34+
print("Banner ad loaded.")
35+
}
36+
37+
func bannerView(_ bannerView: GADBannerView, didFailToReceiveAdWithError error: Error) {
38+
print("Banner ad failed to load: \(error.localizedDescription)")
39+
}
40+
41+
func bannerViewDidRecordImpression(_ bannerView: GADBannerView) {
42+
print("Banner ad recorded an impression.")
43+
}
44+
45+
func bannerViewDidRecordClick(_ bannerView: GADBannerView) {
46+
print("Banner ad recorded a click.")
47+
}
48+
49+
func bannerViewWillPresentScreen(_ bannerView: GADBannerView) {
50+
print("Banner ad will present screen.")
51+
}
52+
53+
func bannerViewWillDismissScreen(_ bannerView: GADBannerView) {
54+
print("Banner ad will dismiss screen.")
55+
}
56+
57+
func bannerViewDidDismissScreen(_ bannerView: GADBannerView) {
58+
print("Banner ad did dismiss screen.")
59+
}
60+
// [END ad_events]
61+
}

Swift/admob/BannerExample/BannerExample/ViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ class ViewController: UIViewController, BannerViewDelegate {
105105

106106
func loadBannerAd() {
107107
// [START ad_size]
108-
// Request an anchored adaptive banner with a width of 375.
109-
bannerView.adSize = currentOrientationAnchoredAdaptiveBanner(width: 375)
108+
// Request a large anchored adaptive banner with a width of 375.
109+
bannerView.adSize = largeAnchoredAdaptiveBanner(width: 375)
110110
// [END ad_size]
111111

112112
// [START load_ad]

0 commit comments

Comments
 (0)