iOS (iPhone, iPad) Tutorial on iOS iAd Integration

iad is used to display ads, served by the apple server. iad helps us in earning revenue from an ios application.

iad integration – steps involved

step 1 − create a simple view-based application.

step 2 − select your project file, then select targets and then add iad.framework in choose frameworks.

step 3 − update viewcontroller.h as follows −

#import <uikit/uikit.h>
#import <iad/iad.h>

@interface viewcontroller : uiviewcontroller<adbannerviewdelegate> {
   adbannerview *bannerview;
}
@end

step 4 − 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

when we run the application, we'll get the following output −

ios tutorial