iAd Tutorial

 How To Integrate iAd Banners Into Your App


1. Register your account for iAd
2. iAd Ad Network at a glance
3. Integrating iAd into your app
4. App Submission
5. Conclusion and Source Code

1. Register your account for iAd

You’re going to need to enroll in the $99/year Apple iOS Developer program in order to enroll for iAd (You need to be enrolled to publish apps to the App Store anyways).

Once you’ve enrolled, you can log on to your iTunes Connect account and then the first thing you’ll need to do is set up your contracts.

iTunes Connect Contracts

On the next screen, request the one for the iAd Ad Network.

iTunes Connect iAd Ad Network Contract

After you click Request, you may be asked to add a new legal entity (person who has the authority to agree to contracts) and then you’ll be asked to review the contract. Once you agree to it and go back to the Contracts screen, you’ll see the pending iAd contract with three more things that you have to set up.

iTunes Pending iAd Contract

Go through each of those buttons and set up your Contact Info, Bank Info and Tax Info. You’ll be guided through the set up by the system.

After you’ve done that, just wait!

2. iAd Ad Network at a glance

For reference, this is the iAd setup guide that I followed from Apple to do my own implementation and it’s what we’ll be walking through together here.

If you follow the link above, you’ll see some high level points about the iAd program and best practices but I’ll list them out here for your convenience:

To Use iAd In Your App, You Must Join the iAd App Network
This is what we’ve already done in step 1.

Banner Views Use a Portion of the Screen to Display a Banner Ad
The first way that you can integrate iAd is with a banner advertisement. Typically it shows up at the bottom of the screen and takes up a portion of the screen.
In this integration, we’ll animate it into view once a banner ad has been downloaded; otherwise, we’ll keep it out of view.

Full-Screen Ads Provide Larger Advertisements to iPad Apps
The second method to integrate iAd is to do full screen ads. For example, if it’s a magazine app, you can add the full screen ad as one of the “pages”. With other types of ads, you can make the full screen ad show up as the user is transitioning from one view to the next.

Pause Nonessential Activities While Users Interact with Advertisements
Once the user taps the ad, it will launch into a full screen interactive experience for the user. This obscures everything happening underneath with the app so it’s recommended that you essentially “pause” your app when this happens.

Canceling Advertising Negatively Impacts Your App
You can programmatically cancel the interactive ad experience and force the user back to your app if your app needs the attention of the user. However, Apple cautions to only do this if absolutely required because it may affect your fill rates.

Fill rate is the rate at which iAd successfully returns an ad for you to display each time your app requests for one. There may be times when your app requests for an ad to show and the iAd ad network returns nothing because it depends on many factors such as their ad inventory.

Validate Your iAd Support Before Releasing Your App
When you’ve integrated iAd and you run your app for testing, you’ll see test ads appear in the place of your banner and full screen ads. Using these test ads, you can make sure that they follow the Human Interface Guidelines for iAd.

3. Integrating iAd into your app

This tutorial will show you how to add the banner ad to the bottom of your app.

Let’s start by creating a sample project that we’re going to integrate the banner in. Open up Xcode 5 and start a new Xcode project. SelectSingle View Application.

iAd single view application

It doesn’t matter what you fill as the project name and identifiers since this is just a demo.

iAd new project settings

At a glance, we’re going to go through these steps:
3.1 – Add the iAd framework to our Xcode project
3.2 – Create, initialize and add the AdBannerView object to our view
3.3 – Animate the banner into view upon a successful ad fetch
3.4 – Handle the case where the app can’t retrieve an ad from the network

3.1 – Add the iAd framework to our Xcode project

Go to your project settings under General:
iAd demo general project settings

Then scroll down to the bottom where you see a section called Linked Frameworks and Libraries. Click the plus icon and search for iAd.

Linked frameworks and libraries

Adding the iAd framework to Xcode

Now you’ve successfully added the iAd framework to the project and we can use the iAd classes!

3.2 – Create, initialize and add the AdBannerView object to our view

Go to ViewController.m and under the viewDidLoad method, add this code:

The lines to note are:

Line 2: We need to import the iAd framework before we can use any of the classes!

Line 16-22: Here we’re overriding the viewDidAppear method, create a new AdBannerView object and then setting its size and position. Finally, we’re adding it to the view.

If you run your application now, you’ll see the banner appear at the bottom of your screen.

iAd banner at the bottom of the view in the iOS Simulator

3.3 – Animate the banner into view upon a successful ad fetch

In order to animate the banner into view, we have to position it out of view initially.

First, we need to make the ViewController conform to the AdBannerDelegate protocol so that the ViewController object can get notified when a banner has successfully been fetched. Only then will we animate the banner in. (If we don’t know when the banner has been fetched, then we don’t know when to animate the banner in!)

So go to ViewController.h and import the framework and conform to the protocol like this:

Then let’s just back and modify the code in ViewController.m slightly.

Notice that these changes:

Line 2: I removed the import statement for the iAd framework here because we’re already doing it in the .H file.

Line 4-7: Notice that we added some instance variables here to keep track of the banner and visible state.

Line 18-24: Notice that we’re now creating the ad banner object and setting it to our instance var. Also notice that the Y-origin is set so that the banner is actually off the bottom of the screen. Finally, we also set the delegate for the banner as “self” which refers to the ViewController object.

Now further down in the same file, let’s implement the AdBanner delegate method that tells us when an ad has successfully been downloaded:

Line 7: Now we’re implementing the delegate methodbannerViewDidLoadAd. This method will trigger when an ad is successfully fetched, however if you didn’t set the ViewController as the delegate for the banner object, then this method won’t fire so make sure you followed the previous step where we set the delegate.

Line 9: Here we check if the banner is visible before doing anything else. The reason is because this method may fire periodically. The banner ad automatically refreshes itself periodically and each time it does, this method will trigger. We only want to animate it in initially.

Line 11-15: Here we add the actual ad banner object into the view since we don’t do that in viewDidAppear anymore.

Line 17-22: Here we animate the banner to slide up from the bottom of the screen. Remember it was initially positioned just off the bottom edge. So now we only need to adjust the Y offset.

Line 24: Finally we set our BOOL flag so that if this method triggers again it won’t try to reanimate it.

Line 28-31: Here we handle the situation where the app fails to retrieve an ad.

During your testing, the iAd network will purposely fail your ad retrieval attempt sometimes so you can test both successful and unsuccessful scenarios. So don’t be alarmed if your ad banner isn’t showing up. Just stop your app and run it again until you get a successful ad.

iAd failed ad retrieval attempt

3.4 – Handle the case where the app can’t retrieve an ad from the network

Line 5: We check if the banner ad is visible because if it’s not, then we don’t have to animate it off the screen.

Line 7-12: In the case that it’s visible, we animate it by sliding it off the bottom of the screen.

Line 14: Finally, we set this flag to NO so that if a banner ad is retrieved successfully, it’ll know that it has to animate the banner view back up.

Now if you run your app, you’ll see the banner ad slide into view upon successful retrieval of an ad. Then if it refreshes and fails to get an ad, it’ll slide out of view.

4. App Submission

So now that your app is showing iAd banners, what do you have to configure in order to show real ads when you submit your app to the app store?


You used to have to configure it in your app catalog listing in iTunes Connect, but not anymore.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: