Set up banner ads

  • Banner ads are rectangular ads that occupy a portion of an app's layout and can be anchored or inline.

  • This guide focuses on implementing anchored adaptive banner ads, which optimize size based on device width.

  • It is crucial to use test ads during development to avoid account suspension.

  • Banner ads are displayed using the GADBannerView object, which can be created programmatically or in Interface Builder.

  • You can listen for banner ad lifecycle events using the GADBannerViewDelegate.

Banner ads are rectangle ads that occupy a portion of an app's layout. Anchored adaptive banners are always on-screen, anchored to the top or bottom of the screen with a maximum height of 20% of the screen size with a 150px max height. To optimize ad size for each device, use adaptive banners.

This guide covers loading an anchored adaptive banner ad into an iOS app.

Prerequisites

Before you continue, set up Google Mobile Ads SDK.

Always test with test ads

When building and testing your apps, make sure you use test ads rather than live, production ads. Failure to do so can lead to suspension of your account.

The easiest way to load test ads is to use our dedicated test ad unit ID for iOS banners:

ca-app-pub-3940256099942544/2435281174

It's been specially configured to return test ads for every request, and you're free to use it in your own apps while coding, testing, and debugging. Just make sure you replace it with your own ad unit ID before publishing your app.

For more information about how Google Mobile Ads SDK test ads work, see Test Ads.

Create a GADBannerView

Banner ads are displayed in GADBannerView objects, so the first step toward integrating banner ads is to include a GADBannerView in your view hierarchy. This is typically done either programmatically or through Interface Builder.

Programmatically

A GADBannerView can also be instantiated directly. The following example creates a GADBannerView:

Swift

// Initialize the banner view.
bannerView = BannerView()
bannerView.