Incorporating ads into your iOS app (using AdMob)

In the previous post I told you that I have a good idea for my next app. I still don’t want to tell you everything about it. But I know that I will need to use a bunch of technologies which I don’t use very frequently:

  1. In-app purchases.
  2. In-app ads.
  3. Local notifications

In fact, up until now I used each of these technologies only once.

In this post we will talk about incorporating ads into your app. Since the last time I used ads in my app things changed. Apple shut down their ads network, called iAd.

That’s not a big problem, though. You just have to use a third party ad network nowadays. I decided to use Google’s AdMob.

How to use AdMob

What you will need:

  1. First of all you need to have an AdMob account.
  2. Register your app in AdMob.
  3. Install AdMob SDK.

By the way, to use AdMob you will also need to download Firebase SDK. Just add these two lines into your Podfile (you need to know how to use CocoaPods):

pod ‘Firebase/Core’
pod ‘Firebase/AdMob’

After the pods are installed, add these lines into your application:didFinishLaunchingWithOptions: method of AppDelegate

You will find your ApplicationID in your AdMob account page.

To add a banner you do something like this in the viewDidLoad method of your view controller:

bannerView’s  class is GADBannerView, which is a subclass of UIView. You can draw your view in the Storyboard and then select this custom subclass for it. Then you connect the view to your view controller through a property bannerView. Also don’t forget to import GoogleMobileAds

You can keep the adUnitID you see above while debugging. You will see a test banner with no real ads on it. But before releasing your app to the App Store you should add real ad unit id. To get it you register your banner in your AdMob account.

When you see real ads in your banner, don’t touch the banner! It’s against the rules.

Basically all you need to know to start using AdMob you can find here:


Leave a Reply

Your email address will not be published. Required fields are marked *