아이폰 App에 들어가는 광고를 달아보겠습니다.
바로 소스파일부터 보겠습니다.
*.h 입니다.
#import <iAd/iAd.h>
@interface xxx : UIViewController <ADBannerViewDelegate>
{
...
...
ADBannerView *bannerView;
BOOL bannerIsVisible;
@interface xxx : UIViewController <ADBannerViewDelegate>
{
...
...
ADBannerView *bannerView;
BOOL bannerIsVisible;
}
- (void)createBannerView;
@property (nonatomic, retain) ADBannerView *bannerView;
@end
- (void)createBannerView;
@property (nonatomic, retain) ADBannerView *bannerView;
@end
그리고
*.m 파일입니다.
@synthesize bannerView;
- (void)viewDidLoad {
...
bannerIsVisible = NO;
[self createBannerView];
}
#pragma mark -
#pragma mark iAds create
- (void) createBannerView
{
if(NSClassFromString(@"ADBannerView")) {
ADBannerView *adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
adView.requiredContentSizeIdentifiers =
[NSSet setWithObjects:ADBannerContentSizeIdentifierPortrait, ADBannerContentSizeIdentifierLandscape, nil];
adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
adView.delegate = self;
adView.frame = CGRectMake(0, 411, 320, 50); //처음위치. 여기서 멍때리고 있다가.. delegate에서 위치를 잡아준다.
self.bannerView = adView;
[self.view addSubview:adView];
bannerIsVisible = NO;
}
}
#pragma mark -
#pragma mark iAD delegate
- (void)bannerViewDidLoadAd:(ADBannerView*)banner
{
if(!bannerIsVisible) {
[UIView beginAnimations:@"animateBannerAppear" context:NULL];
banner.frame = CGRectOffset(banner.frame, 0, -50);
[UIView commitAnimations];
bannerIsVisible = YES;
}
}
- (void)bannerView:(ADBannerView*)banner didFailToReceiveAdWithError:(NSError*)error{
if(bannerIsVisible) {
[UIView beginAnimations:@"animateAdBannerOff" context:NULL];
banner.frame = CGRectOffset(banner.frame, 0, 50);
[UIView commitAnimations];
bannerIsVisible = NO;
}
}
- (void)dealloc {
if(bannerView) {
bannerView.delegate = nil;
[bannerView release];
}
}
- (void)viewDidLoad {
...
bannerIsVisible = NO;
[self createBannerView];
}
#pragma mark -
#pragma mark iAds create
- (void) createBannerView
{
if(NSClassFromString(@"ADBannerView")) {
ADBannerView *adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
adView.requiredContentSizeIdentifiers =
[NSSet setWithObjects:ADBannerContentSizeIdentifierPortrait, ADBannerContentSizeIdentifierLandscape, nil];
adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
adView.delegate = self;
adView.frame = CGRectMake(0, 411, 320, 50); //처음위치. 여기서 멍때리고 있다가.. delegate에서 위치를 잡아준다.
self.bannerView = adView;
[self.view addSubview:adView];
bannerIsVisible = NO;
}
}
#pragma mark -
#pragma mark iAD delegate
- (void)bannerViewDidLoadAd:(ADBannerView*)banner
{
if(!bannerIsVisible) {
[UIView beginAnimations:@"animateBannerAppear" context:NULL];
banner.frame = CGRectOffset(banner.frame, 0, -50);
[UIView commitAnimations];
bannerIsVisible = YES;
}
}
- (void)bannerView:(ADBannerView*)banner didFailToReceiveAdWithError:(NSError*)error{
if(bannerIsVisible) {
[UIView beginAnimations:@"animateAdBannerOff" context:NULL];
banner.frame = CGRectOffset(banner.frame, 0, 50);
[UIView commitAnimations];
bannerIsVisible = NO;
}
}
- (void)dealloc {
if(bannerView) {
bannerView.delegate = nil;
[bannerView release];
}
}
간단하죠~
그리고 당연한 얘기지만,
앱에 올리기 전에 http://developer.apple.com/membercenter/index.action
에서 itunes connect 에서 request를 해줘야 합니다.
그럼 ..
출처 : http://www.devpia.com/Maeul/Contents/Detail.aspx?BoardID=7462&MAEULNo=911&no=52591
'□컴퓨터 관련 > ★iPhone Developer' 카테고리의 다른 글
UITextField X Button Insert (0) | 2010.12.14 |
---|---|
뷰 컨트롤러(UIViewController)의 회전관련 메서드 (0) | 2010.12.13 |
FlowCover reload (0) | 2010.12.08 |
아이폰 OS 개발 자료 총정리 (0) | 2010.12.02 |
Xcode - NavController : Title 색 변경하기 (0) | 2010.12.01 |
gcc failed 발생시 (0) | 2010.11.24 |
xCode NSString 문자열 처리방법 (0) | 2010.07.07 |