ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Technology»
  • Computers & Software»
  • Computer Science & Programming»
  • Computer Programming Tutorials

Create a Mobile Advertising iOS iAd App

Updated on November 14, 2012
klanguedoc profile image

Kevin is Software Developer with 20 years experience designing and building software applications including iOS and Android apps.


(c) 2012 kevin languedoc (klanguedoc)

iAd represents an attractive way to generate income from mobile advertising, hence monetize an iOS iPhone or iPad mobile app. Several hundred developers are generating in the tens of thousands of dollars using this online marketing method which can include small banner ads, full page advertisements or in app purchases. Using the free iAd mobile advertising network from Apple provides a way to offer your iOS app for free but still generate an income. Apple has relationships with all the top brands and advertising agencies so you are insured to have high quality ads from premier corporations.


This guide will provide a high level overview of the iAd API and network, where the network is available and how to setup or enable the iAd network in your applications on the iTunesConnect portal. The guide will also provide a sample app to demonstrate how easy it is to add iAd to your existing or new applications with very little code.

Creating applications for the iPhone, iPad (full size or mini) or iPod Touch that uses the iAd mobile advertising network is an easy process that can be broken down into two large parts. You can to configure your Developer account to use iAds and you have to create an app that implements the ADBannerView and the ADBannerViewDelegate. This guide will provide instructions on both of the steps and provide an ADBannerView and ADBannerViewDelegate examples to show you how to make a mobile application for iPhone, iPad or iPod Touch. The Apple iAd Network in available in these following countries:

United States
United Kingdom

iAd iPhone App Demo

Join iAd Network

The first step to complete to be able to participate in the iAd mobile advertising program is to join the iAd Network through iTunes Connect. Of course you need to be a member of the Apple iOS Developer Program, which cost $99 at the time of this writing. Navigate to the iTunes Portal and login. Then click on the Contracts, Tax, and Banking link. Under the Master Agreements section, you will find the iAd Network setup options. If you haven’t already so, you will need to provide your banking and tax information if you are selling in the United States or other host country, you will need to get your proper tax numbers and fill in the appropriate forms.

You will need to do this configuration to get paid the advertisement revenue that is generated by ads in your apps. Once this is done, you will need to set the preferences and configure iAd in your app.

Manage Your Applications

Again in iTunesConnect, select the “Manage your applications” section and either select an existing app to add iAd to or create a new application profile. Depending on the option you will chose, once the application is created, click on the “Setup iAds” and in the following page ndicate it the app is targeted for users under the age of 17 and click on the “Enable iAds” button. Click on the “Save” button to save your configuration. Next we will create a sample app to test the iAd configuration.

The iAd API

The iAd framework has four classes which are listed here:

  1. ADBannerView
  2. ADInterstitialAd
  3. ADBannerViewDelegate
  4. ADInterstitialAdDelegate

The ADBannerView adds a view to the application to display ads to the user when the app is running on the iPhone, iPad or iPod Touch device. If the user clicks on the ad in the view an action will be triggered and is enabled in the advertisement. The view’s delegate is triggered to cycle through the available ads. The app needs an active Internet connection for this to work, otherwise, view should not display any ads.

The ADInterstitialAd class displays full page advertisement on iPad devices. When the user triggers the ad, a full page ad with its associated rich media is launched, inviting the user to interact with it. Revenue is generated when the user interacts with the ad or view the ad.

If added to the header file that implements the ADBannerView, the ADBannerViewDelegate enables the interactivity of the ADBannerView. the delegate is called when an ad is loaded, thus allowing the user to interact with it.

The ADInterstitialAdDelegate is called when the user interacts with the full page ad in the iPad app when the delegate is added to the header file that implements the ADInterstitialAd class.

UIView as an ADBannerView
UIView as an ADBannerView | Source

Develop Sample iAd App

To demonstrate how easy it is to add iAd functionality to an app, I create a Single-View application to show the basic steps to develop an iAd mobile application.

From the Xcode IDE create a Single-View application. With the application created and loaded in Xcode, select the project root in the project navigator and scroll down to the Linked Libraries and Frameworks section under the Summary page in the right side pane. Click on the “+” button and search for the “iAd” framework and click “Add” to add the framework to your project

Open the storyboard following the addition of the iAd framework and add a UIView to display and interact with iAd network. When adding an UIView I find it useful to stagger it on the previous UIView so as not occupy the full space of the Scene automatically. The screenshot provides a visual aid to help you better understand. Use the handles on the UIView to shrink the width and height of the UIView enough so that it fits within the confines of the Scene.

Set the size and position of the UIView from the Size inspector: x:160, y:25, width:320 height:50. This will position the UIView at the top of the Scene as in the following screenshot. With UIView selected, select the ADBannerView class from the list of available custom class in the Identity inspector in Xcode.

Also open the Editor Assistant (it is the tuxedo icon in the toolbar) and drag a connection (ctrl+drag) from the UIView to the header file to create an IBOutlet. Name the IBOutlet whatever you want so long as you use that value in the code later. For this example, I am naming the IBOutlet: adBannerview.

Close the Editor assistant and open the ViewController header file directly. Import the iAd framework using the import statement and add an instance property for an ADBannerView: adBanner. This object will be added to the UIView that was previously created in the Storyboard.

To be able to interact with the ADBannerView, you will need to implement the ADBannerViewDelegate and its required properties: requiredContentSizeIdentifiers, currentContentSizeIdentifier and sizeFromBannerContentSizeIdentifier, bannerViewActionInProgress as in the following code listing.

In the implementation, add an init method to iniliaze the ADBannerView and the UIView. It is in this method that the adBanner object’s delegate is set. In the viewDidLoad method, the adBanner object is added to the adBannerview after it is initialized and the dimensions are set using the requiredContentSizeIdentifiers and its corresponding properties: ADBannerContentSizeIdentifierPortrait, ADBannerContentSizeIdentifierLandscape.

The other methods are not needed for this simple example. If you run the app as in the followoing video, you will see the richness of the api without additional programming.


//  ViewController.h
//  MobileAds
//  Created by Kevin Languedoc on 11/1/12.
//  Copyright (c) 2012 Kevin Languedoc. All rights reserved.

#import <UIKit/UIKit.h>
#import <iAd/iAd.h>

@interface ViewController : UIViewController<ADBannerViewDelegate>

@property (strong, nonatomic) IBOutlet UIView *adBannerView;
@property (nonatomic, strong) ADBannerView *adBanner;

- (void) bannerViewDidLoadAd;
- (void)bannerViewWillLoadAd:(ADBannerView *)banner;
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error;


//  ViewController.m
//  MobileAds
//  Created by Kevin Languedoc on 11/1/12.
//  Copyright (c) 2012 Kevin Languedoc. All rights reserved.

#import "ViewController.h"

@interface ViewController ()


@implementation ViewController
@synthesize adBannerView;
@synthesize adBanner;

- (void)viewDidLoad
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    adBanner = [[ADBannerView alloc]initWithFrame:CGRectZero];
    adBanner.requiredContentSizeIdentifiers =
    [NSSet setWithObjects:
     ADBannerContentSizeIdentifierLandscape, nil];
    adBanner.delegate = self;
    CGRect contentFrame = self.view.bounds;
    if (contentFrame.size.width < contentFrame.size.height) {
        adBanner.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
    } else {
        adBanner.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
    CGRect bannerFrame = adBanner.frame;
    if (adBanner.bannerLoaded) {
        contentFrame.size.height -= adBanner.frame.size.height;
        bannerFrame.origin.y = contentFrame.size.height;
    } else {
        bannerFrame.origin.y = contentFrame.size.height;

- (void)viewDidUnload
    [self setAdBannerView:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    return YES;
- (void) bannerViewDidLoadAd{
- (void)bannerViewWillLoadAd:(ADBannerView *)banner{
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{


    0 of 8192 characters used
    Post Comment

    No comments yet.