Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ - (void)loadBannerAd {
// The returned ad will be centered in the ad view.

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

// [START load_ad]
Expand Down
18 changes: 18 additions & 0 deletions Objective-C/admob/BannerExample/BannerExample/BannerSnippets.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#import <Foundation/Foundation.h>
#import <GoogleMobileAds/GoogleMobileAds.h>
#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface BannerSnippets : NSObject <GADBannerViewDelegate>

- (void)createCustomAdSizeWithBannerView:(GADBannerView *)bannerView;

- (void)createAdViewWithAdViewContainer:(UIView *)adViewContainer
rootViewController:(UIViewController *)rootViewController;

- (void)loadBannerAdWithBannerView:(GADBannerView *)bannerView;

@end

NS_ASSUME_NONNULL_END
63 changes: 63 additions & 0 deletions Objective-C/admob/BannerExample/BannerExample/BannerSnippets.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#import "BannerSnippets.h"

@implementation BannerSnippets

static NSString *const TestAdUnit = @"ca-app-pub-3940256099942544/2435281174";

- (void)createCustomAdSizeWithBannerView:(GADBannerView *)bannerView {
// [START create_custom_ad_size]
bannerView.adSize = GADAdSizeFromCGSize(CGSizeMake(250, 250));
// [END create_custom_ad_size]
}

// [START create_ad_view]
- (void)createAdViewWithAdViewContainer:(UIView *)adViewContainer
rootViewController:(UIViewController *)rootViewController {
GADBannerView *bannerView = [[GADBannerView alloc] initWithAdSize:GADAdSizeBanner];
bannerView.adUnitID = TestAdUnit;
bannerView.rootViewController = rootViewController;
[adViewContainer addSubview:bannerView];
}
// [END create_ad_view]

// [START load_ad]
- (void)loadBannerAdWithBannerView:(GADBannerView *)bannerView {
// Request a large anchored adaptive banner with a width of 375.
bannerView.adSize = GADLargeAnchoredAdaptiveBannerAdSizeWithWidth(this, 375);
[bannerView loadRequest:[GADRequest request]];
}
// [END load_ad]

// [START ad_events]
#pragma mark - GADBannerViewDelegate

- (void)bannerViewDidReceiveAd:(GADBannerView *)bannerView {
NSLog(@"Banner ad loaded.");
}

- (void)bannerView:(GADBannerView *)bannerView didFailToReceiveAdWithError:(NSError *)error {
NSLog(@"Banner ad failed to load: %@", error.localizedDescription);
}

- (void)bannerViewDidRecordImpression:(GADBannerView *)bannerView {
NSLog(@"Banner ad recorded an impression.");
}

- (void)bannerViewDidRecordClick:(GADBannerView *)bannerView {
NSLog(@"Banner ad recorded a click.");
}

- (void)bannerViewWillPresentScreen:(GADBannerView *)bannerView {
NSLog(@"Banner ad will present screen.");
}

- (void)bannerViewWillDismissScreen:(GADBannerView *)bannerView {
NSLog(@"Banner ad will dismiss screen.");
}

- (void)bannerViewDidDismissScreen:(GADBannerView *)bannerView {
NSLog(@"Banner ad did dismiss screen.");
}
// [END ad_events]

@end
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ - (void)startGoogleMobileAdsSDK {

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

// [START load_ad]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ class ViewController: UIViewController, BannerViewDelegate {
// The returned ad will be centered in the ad view.

// [START ad_size]
// Request an anchored adaptive banner with a width of 375.
bannerView.adSize = currentOrientationAnchoredAdaptiveBanner(width: 375)
// Request a large anchored adaptive banner with a width of 375.
bannerView.adSize = largeAnchoredAdaptiveBanner(width: 375)
// [END ad_size]

// [START load_ad]
Expand Down
61 changes: 61 additions & 0 deletions Swift/admob/BannerExample/BannerExample/BannerSnippets.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import GoogleMobileAds
import UIKit

class BannerSnippets: NSObject, GADBannerViewDelegate {

let testAdUnit = "ca-app-pub-3940256099942544/2435281174"

func createCustomAdSize(bannerView: GADBannerView) {
// [START create_custom_ad_size]
bannerView.adSize = GADAdSizeFromCGSize(CGSize(width: 250, height: 250))
// [END create_custom_ad_size]
}

// [START create_ad_view]
func createAdView(adViewContainer: UIView, rootViewController: UIViewController) {
let bannerView = GADBannerView(adSize: GADAdSizeBanner)
bannerView.adUnitID = testAdUnit
bannerView.rootViewController = rootViewController
adViewContainer.addSubview(bannerView)
}
// [END create_ad_view]

// [START load_ad]
func loadBannerAd(bannerView: GADBannerView) {
// Request a large anchored adaptive banner with a width of 375.
bannerView.adSize = largeAnchoredAdaptiveBanner(width: 375)
bannerView.load(GADRequest())
}
// [END load_ad]

// [START ad_events]
// MARK: - GADBannerViewDelegate methods
func bannerViewDidReceiveAd(_ bannerView: GADBannerView) {
print("Banner ad loaded.")
}

func bannerView(_ bannerView: GADBannerView, didFailToReceiveAdWithError error: Error) {
print("Banner ad failed to load: \(error.localizedDescription)")
}

func bannerViewDidRecordImpression(_ bannerView: GADBannerView) {
print("Banner ad recorded an impression.")
}

func bannerViewDidRecordClick(_ bannerView: GADBannerView) {
print("Banner ad recorded a click.")
}

func bannerViewWillPresentScreen(_ bannerView: GADBannerView) {
print("Banner ad will present screen.")
}

func bannerViewWillDismissScreen(_ bannerView: GADBannerView) {
print("Banner ad will dismiss screen.")
}

func bannerViewDidDismissScreen(_ bannerView: GADBannerView) {
print("Banner ad did dismiss screen.")
}
// [END ad_events]
}
4 changes: 2 additions & 2 deletions Swift/admob/BannerExample/BannerExample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ class ViewController: UIViewController, BannerViewDelegate {

func loadBannerAd() {
// [START ad_size]
// Request an anchored adaptive banner with a width of 375.
bannerView.adSize = currentOrientationAnchoredAdaptiveBanner(width: 375)
// Request a large anchored adaptive banner with a width of 375.
bannerView.adSize = largeAnchoredAdaptiveBanner(width: 375)
// [END ad_size]

// [START load_ad]
Expand Down
Loading