[참고: http://bees4honey.com/blog/tutorial/how-to-add-iad-banner-in-iphoneipad-app/]

필요한 framework : iAd.Framework

1. ziAd.h

#import <Foundation/Foundation.h>
#import <iAd/iAd.h>
@interface ziAd : NSObject <ADBannerViewDelegate>
 
{
    ADBannerView *adBanner;
    BOOL bannerIsVisible;    
}
@property (nonatomic, assign) BOOL bannerIsVisible;
 
- (ADBannerView *)getADBanner;
@end


2. ziAd.m

#import "ziAd.h"
@implementation ziAd
@synthesize bannerIsVisible;

// iAd 배너
 
- (ADBannerView *)getADBanner
{
    adBanner = [[ADBannerView alloc] initWithFrame:CGRectZero];
 
    [adBanner setRequiredContentSizeIdentifiers:
 
    [NSSet setWithObjects:ADBannerContentSizeIdentifierPortrait, nil]];
 
    [adBanner setCurrentContentSizeIdentifier:ADBannerContentSizeIdentifierPortrait];
 
    [adBanner setFrame:CGRectMake(0, 410, 320, 50)];
 
    [adBanner setDelegate:self];
 
    self.bannerIsVisible = NO;
 
    return adBanner;       

}

- (void)bannerViewDidLoadAd:(ADBannerView *)banner

{
    if(!self.bannerIsVisible)
 
    {
        [UIView beginAnimations:@"animateBannerAppear" context:nil];
 
        [adBanner setFrame:CGRectMake(0, 410, 320, 50)];
        [UIView commitAnimations];
 
        self.bannerIsVisible = YES;
 
    }
}

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
 
     if(self.bannerIsVisible)
 
    {
        [UIView beginAnimations:@"animateBannerOff" context:nil];
 
        [adBanner setFrame:CGRectMake(041032050)];
        [UIView commitAnimations];
 
        self.bannerIsVisible = NO;
 
    }
}
@end
// iAd 배너


3. 호출..

#import "ziAd.h"

- (void)viewDidLoad
{
    //iAd
    [self.view addSubview: [[[ziAd alloc]init] getADBanner]];
    [super viewDidLoad];
 
}

//viewWillAppear 에 올리는 방법이 더 좋다고 해서 DidLoad 에서 지웠습니다.

-(void)viewWillAppear:(BOOL)animated
{  
     [self.view addSubview: [[[ziAd alloc]init] getADBanner]];

}


 


저작자 표시
신고
Creative Commons License
Creative Commons License

posted by youp_han matrim



티스토리 툴바