隐藏iAd Banner SKScene

时间:2015-01-26 10:53:41

标签: objective-c xcode iad

嗨大家你认为我应该在Handle Notifications(hideAd,showAd)中使用什么来在我的项目中显示和隐藏我的iAd Banner这里是我用来展示iAd Banner`#import“GameViewController.h”< / p>

导入“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 个答案:

答案 0 :(得分:1)

已加入

- (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];


}
}