Monday 3 February 2014

iAd Framework in iOS

iAd Framework in Xcode


Add the Framework :   iAd.framework

.h File:

#import <iAd/iAd.h>
@interface ViewController : UIViewController<ADBannerViewDelegate>
{
            IBOutlet ADBannerView *adView;
BOOL bannerIsVisible;
}
@property(nonatomic,retain)IBOutlet ADBannerView *adView;
@end;



.m File:

@synthesize adView;

- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
    adView.hidden=NO;
    NSLog(@"adView had ads. Showing.");
}

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
    adView.hidden=YES;
    NSLog(@"adView has no ads. Hiding.");
}

- (void)dealloc
{
    adView.delegate=nil;
    [adView release];
    [super dealloc];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
adView = [[ADBannerView alloc] 
  initWithFrame:CGRectMake(0,0,280,320)];
adView.requiredContentSizeIdentifiers = 
[NSSet setWithObjects: 
ADBannerContentSizeIdentifierPortrait,
ADBannerContentSizeIdentifierLandscape, nil];
self.adView = adView;
adView.delegate = self;
[self.view addSubview:adView];
if ([[[UIDevice currentDevice] systemVersion] compare:@"5.0.1" options:NSNumericSearch] == NSOrderedAscending) {
        
adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierPortrait];
        
        adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
        
        NSLog(@"iOS version is below 5.0.1");
        
    } 
    else 
   {
        
     adView.requiredContentSizeIdentifiers = [NSSet     setWithObject:ADBannerContentSizeIdentifierPortrait];
        
        adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
        
        NSLog(@"iOS version is 5.0.1 or above");
        
    }
}

No comments: