Page Summary
-
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
GADBannerViewobject, which can be created programmatically or in Interface Builder. -
You can listen for banner ad lifecycle events using the
GADBannerViewDelegate.
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.