Skip to content

Commit

Permalink
Making BannerTableViewExample show inline adaptive banner with dynami…
Browse files Browse the repository at this point in the history
…c table view cell height

PiperOrigin-RevId: 618855703
  • Loading branch information
JillSong authored and maddevrelgithubbot committed Mar 25, 2024
1 parent 0a8abd7 commit 4dc91a4
Showing 1 changed file with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
#import "MenuItem.h"
#import "MenuItemTableViewCell.h"

static NSString *const GADAdUnitID = @"ca-app-pub-3940256099942544/2934735716";
static const CGFloat GADAdViewHeight = 100;
static NSString *const GADAdUnitID = @"ca-app-pub-3940256099942544/2435281174";

@interface TableViewController () <GADBannerViewDelegate> {
/// UITableView source items.
Expand Down Expand Up @@ -88,7 +87,7 @@ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPa
if ([_tableViewItems[indexPath.row] isKindOfClass:[GADBannerView class]]) {
GADBannerView *adView = _tableViewItems[indexPath.row];
BOOL isLoaded = [_loadStateForAds[[self referenceKeyForAdView:adView]] boolValue];
return isLoaded ? GADAdViewHeight : 0;
return isLoaded ? CGSizeFromGADAdSize(adView.adSize).height : 0;
}

return UITableViewAutomaticDimension;
Expand Down Expand Up @@ -151,8 +150,8 @@ - (void)addBannerAds {
// Ensure subview layout has been performed before accessing subview sizes.
while (index < _tableViewItems.count) {
GADBannerView *adView = [[GADBannerView alloc]
initWithAdSize:GADAdSizeFromCGSize(
CGSizeMake(self.tableView.contentSize.width, GADAdViewHeight))];
initWithAdSize:GADCurrentOrientationInlineAdaptiveBannerAdSizeWithWidth(
self.tableView.contentSize.width)];
adView.adUnitID = GADAdUnitID;
adView.rootViewController = self;
adView.delegate = self;
Expand All @@ -173,8 +172,6 @@ - (void)preloadNextAd {
GADBannerView *adView = _adsToLoad.firstObject;
[_adsToLoad removeObjectAtIndex:0];
GADRequest *request = [GADRequest request];
GADMobileAds.sharedInstance.requestConfiguration.testDeviceIdentifiers =
@[ GADSimulatorID ]; // Sample device ID
[adView loadRequest:request];
}

Expand Down

0 comments on commit 4dc91a4

Please sign in to comment.