OpenGL Application에 iAD 추가 하는방법

iAD Integration

1. AppDelegate.h 파일에서 다음과 같이 추가한다.
@interface AppDelegate : NSObject {
UIWindow *window;
EAGLView *glView;

UIViewController *adViewController;
BOOL bannerIsVisible;

}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet EAGLView *glView;


@property (nonatomic, retain) IBOutlet UIViewController *adViewController;
@property BOOL bannerIsVisible;



2. AppDelegate.m 에 다음과 같이 추가한다.


@implementation AppDelegate

@synthesize window;
@synthesize glView;
@synthesize adViewController;
@synthesize bannerIsVisible;


- (void) applicationDidFinishLaunching:(UIApplication *)application
{
[glView startAnimation];

[window addSubview:adViewController.view];

bannerIsVisible = NO;
adViewController.view.frame = CGRectOffset(adViewController.view.frame, 0, -50);
}

- (void) applicationWillResignActive:(UIApplication *)application
{
[glView stopAnimation];
}

- (void) applicationDidBecomeActive:(UIApplication *)application
{
[glView startAnimation];
}

- (void)applicationWillTerminate:(UIApplication *)application
{
[glView stopAnimation];
}

- (void) dealloc
{
[adViewController release];
[window release];
[glView release];

[super dealloc];
}


// iAD ---------------------------------------------------------------------------------
- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave
{
NSLog(@"Banner view is beginning an ad action");
BOOL shouldExecuteAction = [self allowActionToRun]; // your application implements this method
if (!willLeave && shouldExecuteAction)
{
// insert code here to suspend any services that might conflict with the advertisement
}
return shouldExecuteAction;
}

- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
if (!self.bannerIsVisible)
{
[UIView beginAnimations:@"animateAdBannerOn" context:NULL];
// assumes the banner view is offset 50 pixels so that it is not visible.
adViewController.view.frame = CGRectOffset(adViewController.view.frame, 0, 50);
[UIView commitAnimations];
self.bannerIsVisible = YES;
}
}

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
if (self.bannerIsVisible)
{
[UIView beginAnimations:@"animateAdBannerOff" context:NULL];
// assumes the banner view is at the top of the screen.
adViewController.view.frame = CGRectOffset(adViewController.view.frame, 0, -50);
[UIView commitAnimations];
self.bannerIsVisible = NO;
}
}


@end


3. MainWindow.xib 에서 UIViewController를 추가한 후 AppDelegate와 연결한다.
4. UiViewController안에 iADBannerView를 추가한 후에 AppDelegate와 연결한다.

이상입니다.

No comments:

Post a Comment