2015-01-26 2 views
0

Привет, ребята Что вы думаете, следует ли использовать в уведомлениях о ручке (hideAd, showAd), чтобы показать и скрыть свой баннер iAd в моем проекте, и вот что я использую для показа iAd Banner `#import" GameViewController .h»Скрыть iAd Banner SKScene

импорта "GameScene.h"

@interface GameViewController() {

bool adOnTop; 
bool iadsBannerIsVisible; 
ADBannerView* theBanner; 

}

@end

@implementation GameViewController 

- (void)viewDidLoad 

{

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:@"hideAd" object:nil]; 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:@"showAd" object:nil]; 


[super viewDidLoad]; 

// Configure the view. 
SKView * skView = (SKView *)self.view; 
skView.showsFPS = YES; 
skView.showsNodeCount = YES; 
skView.multipleTouchEnabled = YES; 
/* Sprite Kit applies additional optimizations to improve rendering performance */ 
skView.ignoresSiblingOrder = YES; 

// Create and configure the scene. 
GameScene *scene = [GameScene sceneWithSize:skView.bounds.size]; 
scene.scaleMode = SKSceneScaleModeAspectFit; 

// Present the scene. 
[skView presentScene:scene]; 

[self showThinBanner]; 

}

-(void) showThinBanner { 
iadsBannerIsVisible = YES; 
theBanner = [[ADBannerView alloc] initWithFrame:CGRectZero]; 
[theBanner setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; 
theBanner.delegate = self; 


[self.view addSubview:theBanner]; 

}

- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave { 
NSLog(@"Banner view is beginning an ad action"); 
BOOL shouldExecuteAction = YES; // your app implements this method 

if (!willLeave && shouldExecuteAction){ 
    // insert code here to suspend any services that might conflict with the advertisement, for example, you might pause the game with an NSNotification like this... 
    [[NSNotificationCenter defaultCenter] postNotificationName:@"PauseScene" object:nil]; //optional 
} 
return shouldExecuteAction; 

}

-(void) bannerViewActionDidFinish:(ADBannerView *)banner { 
NSLog(@"banner is done being fullscreen"); 
//Unpause the game if you paused it previously. 
[[NSNotificationCenter defaultCenter] postNotificationName:@"UnPauseScene" object:nil]; //optional 

}

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error 
{ 



    if (iadsBannerIsVisible == YES) { 

     [UIView beginAnimations:@"animateAdBannerOff" context:NULL]; 
     // Assumes the banner view is placed at the bottom of the screen. 
     banner.frame = CGRectOffset(banner.frame, 0, banner.frame.size.height); 
     [UIView commitAnimations]; 
     iadsBannerIsVisible = NO; 

     NSLog(@"banner unavailable"); 
    } 
    } 



- (void)handleNotification:(NSNotification *)notification 


{ 
if ([notification.name isEqualToString:@"hideAd"]) 
    { 
     // hide your banner; 
}else if ([notification.name isEqualToString:@"showAd"]) 
    { 
     // show your banner 
} 


} 

ответ

1

Sloved

- (void)handleNotification:(NSNotification *)notification 
{ 
if ([notification.name isEqualToString:@"hideAd"]) 
{ 
    // hide your banner; 



    [theBanner removeFromSuperview]; 




}else if ([notification.name isEqualToString:@"showAd"]) 
{ 
    // show your banner 

    [self.view addSubview:theBanner]; 


} 
} 
Смежные вопросы