필요한 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(0, 410, 320, 50)];
[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]];
}
'초짜 IT보이 서바이벌 스토리 > iOS - Objective-C' 카테고리의 다른 글
[Obejective-C] Royalty Waived Transactions 가 뭘까요? (0) | 2012.02.28 |
---|---|
[Obejective-C] 아이폰 사용자 언어 (0) | 2012.02.27 |
#AppStore 등록 후 기다리는 동안.. (0) | 2012.01.28 |
[Obejective-C] TextField 암호 입력 시 (0) | 2011.12.16 |
[Obejective-C] NSString <-> int 변환하기 (0) | 2011.12.09 |