Easy Tutorial
❮ Att Ios Ui Alerts Att Ios Ui Status Bar ❯

iOS iAD Integration


Introduction

iAD is Apple's advertising platform, which helps developers earn revenue from their applications.

Example Steps

  1. Create a simple View-based application.

  2. Select the project file, then select the target, and then select the framework and add iAd.framework.

  3. Update ViewController.h as shown below

    #import <UIKit/UIKit.h>
    #import <iAd/iAd.h>
    @interface ViewController : UIViewController<ADBannerViewDelegate>
    {
        ADBannerView *bannerView;
    }
    @end
    
  4. Update ViewController.m as shown below

    #import "ViewController.h"
    
    @interface ViewController ()
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        bannerView = [[ADBannerView alloc]initWithFrame:
        CGRectMake(0, 0, 320, 50)];
        // Optional to set background color to clear color
        [bannerView setBackgroundColor:[UIColor clearColor]];
        [self.view addSubview: bannerView];
    }
    
    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    #pragma mark - AdViewDelegates
    
    -(void)bannerView:(ADBannerView *)banner 
     didFailToReceiveAdWithError:(NSError *)error{
        NSLog(@"Error loading");
    }
    
    -(void)bannerViewDidLoadAd:(ADBannerView *)banner{
        NSLog(@"Ad loaded");
    }
    -(void)bannerViewWillLoadAd:(ADBannerView *)banner{
        NSLog(@"Ad will load");
    }
    -(void)bannerViewActionDidFinish:(ADBannerView *)banner{
        NSLog(@"Ad did finish");
    
    }
    @end
    

Output

Run the application to get the following output:

❮ Att Ios Ui Alerts Att Ios Ui Status Bar ❯