Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

iOS Integrating iAD

IOS iAD Integration


Introduction

IAD is an advertising platform launched by Apple; it can help developers generate revenue from their applications.

Example Steps

  1. Create a simple View based application

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

  3. Update ViewController.h as follows



#import 

#import 

@interface ViewController : UIViewController

{

    ADBannerView *bannerView;

}

@end

  1. Update ViewController.m as follows


#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:

iAdOutput