Skip to content

Commit

Permalink
Banner example will display an anchored adaptive banner.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 578505366
  • Loading branch information
JillSong authored and maddevrelgithubbot committed Nov 1, 2023
1 parent fa423b2 commit 42e1ac9
Show file tree
Hide file tree
Showing 86 changed files with 162 additions and 3,006 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (C) 2014 Google LLC
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,6 @@
//

#import "AppDelegate.h"
#import <GoogleMobileAds/GoogleMobileAds.h>

@interface AppDelegate ()

Expand All @@ -25,42 +24,7 @@ @implementation AppDelegate

- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.

// Initialize Google Mobile Ads SDK
[GADMobileAds.sharedInstance startWithCompletionHandler:nil];
return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
// Sent when the application is about to move from active to inactive state. This can occur for
// certain types of temporary interruptions (such as an incoming phone call or SMS message) or
// when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame
// rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store
// enough application state information to restore your application to its current state in case
// it is exited later.
// If your application supports background execution, this method is called instead of
// applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
// Called as part of the transition from the background to the inactive state; here you can undo
// many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If
// the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to exit. Save data if appropriate. See also
// applicationDidEnterBackground:.
}

@end
Original file line number Diff line number Diff line change
@@ -1,70 +1,81 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="21507" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" colorMatched="YES" initialViewController="I2k-Tk-Ql0">
<device id="retina6_12" orientation="portrait" appearance="light"/>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="22154" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" colorMatched="YES" initialViewController="hrC-kg-0cx">
<device id="retina5_9" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21505"/>
<deployment version="2304" identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22130"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Navigation Controller-->
<scene sceneID="6Vs-oQ-PZA">
<scene sceneID="C4n-XQ-wRB">
<objects>
<navigationController id="I2k-Tk-Ql0" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="mvh-jd-d5M">
<rect key="frame" x="0.0" y="59" width="393" height="44"/>
<navigationController id="hrC-kg-0cx" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="FPg-sG-Arc">
<rect key="frame" x="0.0" y="50" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<connections>
<segue destination="BYZ-38-t0r" kind="relationship" relationship="rootViewController" id="BT4-IE-4oK"/>
<segue destination="BYZ-38-t0r" kind="relationship" relationship="rootViewController" id="Uds-uW-h0Q"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="79R-RW-eZH" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="uSn-6A-8ax" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-1355" y="296"/>
<point key="canvasLocation" x="-1388" y="-1360"/>
</scene>
<!--View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="SFb-1a-qlX"/>
<viewControllerLayoutGuide type="bottom" id="LF1-Ug-RAX"/>
<viewControllerLayoutGuide type="top" id="tbf-Mn-K5I"/>
<viewControllerLayoutGuide type="bottom" id="VPC-wN-zKU"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="393" height="852"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="812"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="jPL-30-0SK" customClass="GAMBannerView">
<rect key="frame" x="36.666666666666657" y="768" width="320" height="50"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" constant="50" id="ZaG-Ct-7iz"/>
<constraint firstAttribute="width" constant="320" id="fpu-sd-d1g"/>
</constraints>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Banner Example" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ChV-Lb-5si">
<rect key="frame" x="104" y="144" width="167" height="29"/>
<fontDescription key="fontDescription" type="system" pointSize="24"/>
<color key="textColor" systemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<view contentMode="scaleToFill" placeholderIntrinsicWidth="320" placeholderIntrinsicHeight="50" translatesAutoresizingMaskIntoConstraints="NO" id="b5b-Tm-bLe" customClass="GAMBannerView">
<rect key="frame" x="27.666666666666657" y="728" width="320" height="50"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="LF1-Ug-RAX" firstAttribute="top" secondItem="jPL-30-0SK" secondAttribute="bottom" id="OZR-Fx-FSc"/>
<constraint firstItem="jPL-30-0SK" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="TDu-IU-gjl"/>
<constraint firstAttribute="centerX" secondItem="ChV-Lb-5si" secondAttribute="centerX" id="NIs-CX-Ldp"/>
<constraint firstItem="b5b-Tm-bLe" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="WeT-da-GCk"/>
<constraint firstItem="ChV-Lb-5si" firstAttribute="top" secondItem="tbf-Mn-K5I" secondAttribute="bottom" constant="50" id="cAO-jl-Cb8"/>
<constraint firstItem="VPC-wN-zKU" firstAttribute="top" secondItem="b5b-Tm-bLe" secondAttribute="bottom" id="gEX-fN-fGB"/>
</constraints>
</view>
<navigationItem key="navigationItem" id="lTn-F8-vJq">
<barButtonItem key="rightBarButtonItem" enabled="NO" title="Privacy Settings" id="Yww-jA-bXG">
<toolbarItems/>
<navigationItem key="navigationItem" id="OeE-zL-ruC">
<barButtonItem key="rightBarButtonItem" enabled="NO" title="Privacy Settings" id="D2V-uK-vBr">
<connections>
<action selector="privacySettingsTapped:" destination="BYZ-38-t0r" id="GiJ-B4-wKI"/>
<action selector="privacySettingsTapped:" destination="BYZ-38-t0r" id="35e-S9-mPt"/>
</connections>
</barButtonItem>
</navigationItem>
<nil key="simulatedBottomBarMetrics"/>
<connections>
<outlet property="bannerView" destination="jPL-30-0SK" id="rUl-2d-laY"/>
<outlet property="privacySettingsButton" destination="Yww-jA-bXG" id="WSz-kj-LSr"/>
<outlet property="bannerView" destination="b5b-Tm-bLe" id="cWf-NW-i8E"/>
<outlet property="privacySettingsButton" destination="D2V-uK-vBr" id="eKt-Ys-Cxs"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-160" y="296"/>
<point key="canvasLocation" x="-190.40000000000001" y="-1359.2203898050975"/>
</scene>
</scenes>
<resources>
<systemColor name="darkTextColor">
<color white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
</resources>
</document>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (C) 2023 Google LLC
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (C) 2023 Google LLC
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (C) 2014 Google LLC
// Copyright (C) 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -20,7 +20,7 @@

@interface ViewController : UIViewController

/// The Google Ad Manager banner view.
@property(nonatomic, weak) IBOutlet GAMBannerView *bannerView;
@property(weak, nonatomic) IBOutlet UIBarButtonItem *privacySettingsButton;

@end
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (C) 2014 Google LLC
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -20,11 +20,7 @@

#import "GoogleMobileAdsConsentManager.h"

@interface ViewController () <GADBannerViewDelegate>

@property(weak, nonatomic) IBOutlet UIBarButtonItem *privacySettingsButton;

@end
#import "ViewController.h"

@implementation ViewController

Expand Down Expand Up @@ -54,10 +50,7 @@ - (IBAction)privacySettingsTapped:(UIBarButtonItem *)sender {
- (void)viewDidLoad {
[super viewDidLoad];

// Replace this ad unit ID with your own ad unit ID.
self.bannerView.adUnitID = @"/6499/example/banner";
self.bannerView.rootViewController = self;
self.bannerView.delegate = self;

__weak __typeof__(self) weakSelf = self;
[GoogleMobileAdsConsentManager.sharedInstance
Expand Down Expand Up @@ -88,46 +81,45 @@ - (void)viewDidLoad {
}
}

- (void)viewWillTransitionToSize:(CGSize)size
withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
[coordinator
animateAlongsideTransition:^(
id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
[self loadBannerAd];
}
completion:nil];
}

- (void)startGoogleMobileAdsSDK {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
// Initialize the Google Mobile Ads SDK.
[GADMobileAds.sharedInstance startWithCompletionHandler:nil];

// Request an ad.
[self.bannerView loadRequest:[GAMRequest request]];
[self loadBannerAd];
});
}

#pragma mark GADBannerViewDelegate implementation

- (void)bannerViewDidReceiveAd:(GADBannerView *)bannerView {
NSLog(@"bannerViewDidReceiveAd");
}

- (void)bannerView:(GADBannerView *)bannerView didFailToReceiveAdWithError:(NSError *)error {
NSLog(@"bannerView:didFailToReceiveAdWithError: %@", [error localizedDescription]);
}

- (void)bannerViewDidRecordImpression:(GADBannerView *)bannerView {
NSLog(@"bannerViewDidRecordImpression");
}
- (void)loadBannerAd {
// Here safe area is taken into account, hence the view frame is used after the
// view has been laid out.
CGRect frame = UIEdgeInsetsInsetRect(self.view.frame, self.view.safeAreaInsets);
CGFloat viewWidth = frame.size.width;

- (void)bannerViewWillPresentScreen:(GADBannerView *)bannerView {
NSLog(@"bannerViewWillPresentScreen");
}
// Replace this ad unit ID with your own ad unit ID.
self.bannerView.adUnitID = @"/30497360/adaptive_banner_test_iu/backfill";

- (void)bannerViewWillDismissScreen:(GADBannerView *)bannerView {
NSLog(@"bannerViewWillDismissScreen");
}
// Here the current interface orientation is used. If the ad is being preloaded
// for a future orientation change or different orientation, the function for the
// relevant orientation should be used.
GADAdSize adaptiveSize = GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(viewWidth);

- (void)bannerViewDidDismissScreen:(GADBannerView *)bannerView {
NSLog(@"bannerViewDidDismissScreen");
}
// Note that Google may serve any reservation ads that that are smaller than
// the adaptive size as outlined here - https://support.google.com/admanager/answer/9464128.
// The returned ad will be centered in the ad view.
self.bannerView.adSize = adaptiveSize;

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
[self.bannerView loadRequest:[GAMRequest request]];
}

@end
2 changes: 1 addition & 1 deletion Objective-C/admanager/AdManagerBannerExample/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: e85d5d9b3c666bb8f015ed22050958cf6d874cb5

COCOAPODS: 1.13.0
COCOAPODS: 1.14.0
Loading

0 comments on commit 42e1ac9

Please sign in to comment.