How to Integrate AdMob Banner Ads, Interstitial Ads with iOS Apps using Google Mobile Ads SDK

Varun Kumar
5 min readApr 13, 2021

To use AdMob in your apps, you will need to use the Google Mobile Ads SDK. The integration is not difficult. To display a simple ad banner, it just takes a few lines of code and you’re ready to start making a profit from your app.

Apply a Google AdMob Account

Before you can integrate your apps with Google AdMob, you’ll need to first enroll in the AdMob service. Now open the link below using Safari browser.

https://admob.google.com

AdMob is now part of Google, you can simply sign in with your Google account or register a new one. AdMob requires you to have a valid AdSense account and AdWords account. If you don’t have one or both of these accounts, follow the sign-up process and connect them to your Google Account.

Once you finish the registration, you will be brought to the AdMob dashboard. In the navigation on your left, select the Apps option.

AdMob Dashboard

Here, choose the Add Your First App option. Choose the iOS Platform. AdMob will first ask you if your app has been published on the App Store. Assuming your app has not been published, choose the option “No”. We will register the app by filling in the form manually. In the future, if you already have an app on the App Store, you can let yes the app is listed on a supported app store.

Register the App

Set the app name to GoogleAdMobDemo. Click Add APPto proceed to the next step. Then click to Done.

AdMob will then generate an App ID for the app. Please make a note of this app ID. We will need to add it to our app in order to integrate with AdMob.

Your AdMob App ID

Setup the BannerAds at Admob Dashboard.

Next, we need to create at least an ad unit. Click Next: Create Ad Unit to proceed. In this demo, we use the banner ad. Select Banner and accept the default options. For the Ad unit name, set it to Banner Ad.

Click Done to generate the ad unit ID. This completes the configuration of your new app. You will find the App ID and Ad unit ID in the implementation instructions. Please save this information. We will need them in the later section when we integrate AdMob with our Xcode project.

Using Google Mobile Ads Framework

Now that we have completed the configuration in AdMob, let’s move to the actual implementation. To integrate Google AdMob into your app, the first thing you need to do is install the Google Mobile Ads framework into the Xcode project. All you need is to create a Podfile in your Xcode project, and then add the following line to your app’s target in the file:

pod 'Google-Mobile-Ads-SDK'

Then you run pod install to grab the SDK, and let CocoaPods integrate the SDK into your Xcode project.

To use the Google Mobile Ads SDK in your code, need to add the GADApplicationIdentifier key with string value App ID in your info.plist file.
In case you have not copied the App ID you will find it in the App Settings left of your Admob Dashboard. Please make sure you replace the App ID.

info.plist file
Admod dashboard

Displaying Banner Ads at Bottom of UIViewController.

Let’s start with the simplest way to display a banner ad in your app. We will request an ad banner from Google and display the ad at the bottom of our ViewController.

To display a banner ad at that position, all you need to do is create an IBoutlet GADBannerView object, Create a method load banner in that set its delegate, bannerID Then you call its load method with an ad request to retrieve a banner ad. When the ad is ready to display, it will call the adViewDidReceiveAd(bannerView:) method of the GADBannerViewDelegate protocol. So you just need to implement the method to show the banner ad.

Okay, let’s now go into the implementation.

Banner Ad at bottom

Setup the Interstitial Ads atAdmob Dashboard.

Interstitial ads are full-screen ads that cover the interface of their host app. They’re typically displayed at natural transition points in the flow of an app, such as between activities or during the pause between levels in a game.

To do that, you have to first go back to AdMob’s dashboard (https://apps.admob.com) to create an interstial ad for the demo app. Select Apps in the side menu and choose GoogleAdMobDemo. In the next screen, click Add Ad Unit to create a new ad unit. Select the interstitial ad add the name InterstitialAd and click on Done.

Displaying Interstitial Ad.

The code of implementing an interstitial ad is very similar to that of a banner ad. Instead of using the GADBannerView class, you use the GADInterstitial class. So, declare a variable for storing the GADInterstitial object in the ViewController.

var interstitial: GADInterstitialAd?

We first initialize a GADInterstitial object. Then we create a GADRequest, call the load method with the ad unit ID (remember to replace it with yours) and set the delegate to self.

We need to adopt a protocol in order to check the status of an ad. Create an extension to implement the GADInterstitialDelegate protocol:

We will create the ad when the view is loaded. Call loadInterstitial method in the viewDidLoad()method.

--

--