Created
October 25, 2012 20:21
-
-
Save takatoshi/3955157 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import "example.h" | |
| // *** 追加 *** // | |
| #import "AdWhirlView.h" | |
| #import "AppDelegate.h" | |
| @implementation example | |
| // *** 追加 *** // | |
| @synthesize adView; | |
| - (id)init { | |
| if (self = [super init]) { | |
| // *** 通常のコード *** // | |
| } | |
| return self; | |
| } | |
| - (void)dealloc { | |
| // *** 追加 *** // | |
| self.adView.delegate = nil; | |
| self.adView = nil; | |
| // *** 通常のコード *** // | |
| [super dealloc]; | |
| } | |
| // *** ここからすべて追加 *** // | |
| // 広告をクリックして全画面表示されたときに実行される関数 | |
| - (void)adWhirlWillPresentFullScreenModal { | |
| CCLOG(@"%@: %@", NSStringFromSelector(_cmd), self); | |
| } | |
| // 広告の全画面表示が閉じられたときに実行される関数 | |
| - (void)adWhirlDidDismissFullScreenModal { | |
| CCLOG(@"%@: %@", NSStringFromSelector(_cmd), self); | |
| } | |
| - (NSString *)adWhirlApplicationKey { | |
| CCLOG(@"%@: %@", NSStringFromSelector(_cmd), self); | |
| // *** AdWhirlのSDK Keyを入力*** // | |
| return @"****************************"; | |
| } | |
| - (UIViewController *)viewControllerForPresentingModalView { | |
| CCLOG(@"%@: %@", NSStringFromSelector(_cmd), self); | |
| // *** cocos2dでは、ここをviewControllerにしないと,AdMobが機能しない *** // | |
| return viewController; | |
| } | |
| // 広告を受信したら実行される関数 | |
| -(void)adWhirlDidReceiveAd:(AdWhirlView *)adWhirlView { | |
| CCLOG(@"%@: %@", NSStringFromSelector(_cmd), self); | |
| [self adjustAdSize]; | |
| } | |
| // 広告のサイズを調整する関数。今回は必須ではない | |
| -(void)adjustAdSize { | |
| CCLOG(@"%@: %@", NSStringFromSelector(_cmd), self); | |
| CGSize screenSize = [[CCDirector sharedDirector] winSize]; | |
| [UIView beginAnimations:@"AdResize" context:nil]; | |
| [UIView setAnimationDuration:0.7]; | |
| CGSize adSize = [adView actualAdSize]; | |
| CGRect newFrame = adView.frame; | |
| newFrame.size.height = adSize.height; | |
| newFrame.size.width = screenSize.width; | |
| newFrame.origin.x = (self.adView.bounds.size.width - adSize.width)/2; | |
| newFrame.origin.y = (screenSize.height - adSize.height); | |
| adView.frame = newFrame; | |
| [UIView commitAnimations]; | |
| } | |
| // 広告の受信を失敗したときに実行される関数 | |
| -(void)adWhirlDidFailToReceiveAd:(AdWhirlView *)adWhirlView usingBackup:(BOOL)yesOrNo { | |
| CCLOG(@"%@: %@", NSStringFromSelector(_cmd), self); | |
| } | |
| -(void)onEnter { | |
| CCLOG(@"%@: %@", NSStringFromSelector(_cmd), self); | |
| // *** 通常のコード *** // | |
| // *** ここから追加。広告を表示部分 *** // | |
| CGSize screenSize = [[CCDirector sharedDirector] winSize]; | |
| viewController = [(AppDelegate*)[[UIApplication sharedApplication] delegate] viewController]; | |
| self.adView = [AdWhirlView requestAdWhirlViewWithDelegate:self]; | |
| self.adView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin; | |
| [adView updateAdWhirlConfig]; | |
| CGSize adSize = [adView actualAdSize]; | |
| self.adView.frame = CGRectMake((screenSize.width/2)-(adSize.width/2),screenSize.height-adSize.height,screenSize.width,adSize.height); | |
| self.adView.clipsToBounds = YES; | |
| [viewController.view addSubview:adView]; | |
| [viewController.view bringSubviewToFront:adView]; | |
| [super onEnter]; | |
| } | |
| -(void)onExit { | |
| CCLOG(@"%@: %@", NSStringFromSelector(_cmd), self); | |
| // *** 通常のコード *** // | |
| // *** ここから追加。広告削除部分 *** // | |
| if (adView) { | |
| [adView removeFromSuperview]; | |
| [adView replaceBannerViewWith:nil]; | |
| [adView ignoreNewAdRequests]; | |
| [adView setDelegate:nil]; | |
| [adView release]; | |
| adView = nil; | |
| } | |
| [super onExit]; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment