如何正确地隐藏这些广告横幅? [英] How to properly hide these ad banners?

查看:300
本文介绍了如何正确地隐藏这些广告横幅?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(雪碧套装游戏),我想在游戏中被隐藏我的广告横幅。我已经设置了我的项目,同时包含的iAd和AdMob的广告横幅。在此之前,在AdMob的SDK和code的AdMob的广告加入,我没有问题,与隐藏iAd的横幅时,我想它隐藏起来。现在有,因为出了问题怎么我的code设置,我似乎无法修复:

(Sprite Kit Game) I want my ad banners to be hidden during gameplay. I've set up my project to contain both iAd and AdMob advertisement banners. Prior to adding in the AdMob SDK and the code for the AdMob advertisements, I had no problem with hiding the iAd banner when I wanted it hidden. Now there is a problem because of how my code is set up and I can't seem to fix it:

这是在code:

    - (void)viewDidLoad
{
    [super viewDidLoad];

    //Add view controller as observer
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:@"hideAd" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:@"showAd" object:nil];

    // Present the scene.
    [skView presentScene:scene];
    self.canDisplayBannerAds = YES;

    appleAd = [[ADBannerView alloc] initWithFrame:CGRectZero];
    appleAd.frame = CGRectOffset(appleAd.frame, 0, 0.0f);
    appleAd.delegate = self;
    //hide the apple ad so it appears when told to 
    appleAd.alpha = 0;
    [self.view addSubview:appleAd];

    //google ad
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        googleBanner_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeLeaderboard origin:CGPointMake(20, 0)];
    }else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
        googleBanner_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner origin:CGPointMake(0, 100)];
    }
    googleBanner_.adUnitID = @"•••••••••••••••••••••••••pub";
    googleBanner_.rootViewController = self;
    [self.view addSubview:googleBanner_];

    [googleBanner_ loadRequest:[GADRequest request]];

    GADRequest *request = [GADRequest request];
    request.testDevices = @[ @"•••••••••••••••••••••••" ];

    //hide the google advertisement when it loads because prioritising iAd and so it appears when told to 
    googleBanner_.alpha = 0;

}

-(void)handleNotification:(NSNotification *)notification {
    if ([notification.name isEqualToString:@"hideAd"]) {
        [self hidesBanner];
    }else if ([notification.name isEqualToString:@"showAd"]){
        [self showsBanner];
    }
}

//THIS IS WHERE THE ISSUES ARE: 
-(void)showsBanner {
    NSLog(@"Showing Banner");
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1.0];
    [appleAd setAlpha:1];
    [UIView commitAnimations];

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1.0];
    [googleBanner_ setAlpha:1];
    [UIView commitAnimations];

    if (appleAd.alpha == 1) {
        googleBanner_.alpha = 0;
        NSLog(@"google banner is hidden");
    }
}
-(void)hidesBanner{
    NSLog(@"Hiding Banner");
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0];
    [appleAd setAlpha:0];
    [UIView commitAnimations];

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0];
    [googleBanner_ setAlpha:0];
    [UIView commitAnimations];

    if (appleAd.alpha == 0) {
        googleBanner_.alpha = 1.0;
        NSLog(@"google banner is showing");
    }
}

//iAd delegate
#pragma mark iAd Delegate Methods

-(void)bannerViewDidLoadAd:(ADBannerView *)banner {
    //iAd
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1.0];
    [appleAd setAlpha:1];
    [UIView commitAnimations];

    //googleAd
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0];
    [googleBanner_ setAlpha:0];
    [UIView commitAnimations];
}

-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
    //iAd
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0];
    [appleAd setAlpha:0];
    [UIView commitAnimations];

    //googleAd
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1.0];
    [googleBanner_ setAlpha:1.0];
    [UIView commitAnimations];
}

正如你所看到的问题是内部的隐藏和显示广告的方法。它只是表明这两个广告在同一时间。我不知道如何保持持续的补充,当我要显示和隐藏的广告。当我没有隐藏的广告针对特定场景的补充工作正常(AdMob的时出现的iAd不可用),所以它肯定与方法问题。我以为编辑是这样的:

As you can see the problem is inside the hide and show ad methods. It simply shows both advertisements at the same time. I'm not sure how to keep the supplementation going when I want to show and hide the ad. When I don't have to hide the ad for specific scenes, the supplementation works fine (AdMob appears when iAd is unavailable), so it's definitely a problem with those methods. I thought to edit them like this:

 -(void)showsBanner {
    NSLog(@"Showing Banner");
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1.0];
    [appleAd setAlpha:1];
    [UIView commitAnimations];
}
-(void)hidesBanner{
    NSLog(@"Hiding Banner");
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0];
    [appleAd setAlpha:0];
    [UIView commitAnimations];
}

要$ P $从冲突的pvent他们。我认为这将只是回落到编译标志的iAd代表和补充谷歌的广告。它没有工作。

To prevent them from conflicting. I assumed this would just fall back to the pragma mark iAd delegate and supplement the google ad. It didn't work.

我怎样才能让这个我可以告诉他们需要显示在某一时间在一个场景两个广告,但也有补充出现?有什么建议?

推荐答案

您可以使用BOOL作为开关为显示appleAd或googleBanner,或者什么,你可能想:

You could use a BOOL as a switch to show either appleAd or googleBanner, or none as you might want:

在您的.h文件中:

BOOL isAppleAd;
BOOL isGoogleAd;

然后做这样的事情:

Then do something like this:

- (void)showsBanner {

    if (isAppleAd == YES) {
        [self appleAd];
    }
    if (isGoogleAd == YES) {
        [self googleAd];
    }
    else {
        [self hideBothBanners];
    }

}

- (void)appleAd {

        if (isAppleAd == YES) {

        NSLog(@"Showing Apple Banner");

        //googleAd OFF
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0];
        [googleBanner_ setAlpha:0];
        [UIView commitAnimations];

        // iAd ON
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:1.0];
        [appleAd setAlpha:1.0];
        [UIView commitAnimations];

        // switch off AppleAd to use as switch
        isAppleAd = NO;
        isGoogleAd = YES;

    } else {
        // do something else
        return;
    }

}

- (void)googleAd {

    if (isGoogleAd == YES) {

        NSLog(@"Showing Google Banner");

        // iAd OFF
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0];
        [appleAd setAlpha:0];
        [UIView commitAnimations];

        // googleAd ON
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:1.0];
        [googleBanner_ setAlpha:1.0];
        [UIView commitAnimations];

        // switch off GoogleAd to use as switch
        isGoogleAd = NO;
        isAppleAd = YES;

    } else {
        // do something else
        return;
    }

}

- (void)hideBothBanners {

        NSLog(@"Hiding Both Banners");

        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0];
        [appleAd setAlpha:0];
        [googleBanner_ setAlpha:0]
        [UIView commitAnimations];

}

这篇关于如何正确地隐藏这些广告横幅?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆