简体   繁体   English

在Spritekit场景中隐藏iAd BannerView

[英]Hide iAd bannerview in spritekit scene

I am trying to add iads to my new sprite kit game. 我正在尝试将iads添加到新的Sprite Kit游戏中。 The problem is that i do not need the ad to be on all the scenes. 问题是我不需要所有场景的广告。 I've started to create an ADBannerView in the mainstoryboard. 我已经开始在主板上创建ADBannerView。 After that i'm trying to use NSNotification to hide and show the ads in different scenes, but its not working. 之后,我尝试使用NSNotification隐藏和显示广告在不同的场景,但它不起作用。 the ad is still showing even though i've added into Menu.m(scene): 即使我已添加到Menu.m(scene),广告仍在展示:

[[NSNotificationCenter defaultCenter] postNotificationName:@"hideAd" object:nil];

ViewController.m ViewController.m

-(void)viewWillLayoutSubviews {

    [super viewWillLayoutSubviews];
    // Configure the view.
    SKView * skView = (SKView *)self.view;
    //skView.showsFPS = YES;
    //skView.showsNodeCount = YES;
    //skView.showsPhysics = YES;


    if (!skView.scene) {


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



        SKScene * scene = [Menu sceneWithSize:skView.bounds.size];

        NSLog(@"%@", scene);

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






    }

}

-(void)bannerViewDidLoadAd:(ADBannerView *)banner {

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


    }

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

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


}

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


-(void)hidesBanner {

    NSLog(@"HIDING BANNER");
    [adView setAlpha:0];

}


-(void)showsBanner {

    NSLog(@"SHOWING BANNER");
    [adView setAlpha:1];


}

It is not good to create an iAd if you do not intend to show it. 如果您不想显示iAd,则创建iAd不好。

According to Apple's Banner View Best Practices : 根据Apple的Banner查看最佳做法

• Only create a banner view when you intend to display it to the user. •仅在打算将其显示给用户时创建横幅视图。 Otherwise, it may cycle through ads and deplete the list of available advertising for your app. 否则,它可能会在广告中循环播放,并耗尽您应用的可用广告列表。

• If the user navigates from a screen of content with a banner view to a screen that does not have a banner view, and you expect them to be on that screen for a long period of time, remove the banner view from the view hierarchy, set its delegate to nil and release it before transitioning to the new screen of content. •如果用户从具有横幅视图的内容屏幕导航到没有横幅视图的屏幕,并且您希望他们在该屏幕上停留很长时间,请从视图层次结构中删除横幅视图,将其委托设置为nil并释放它,然后再过渡到新的内容屏幕。 More generally, avoid keeping a banner view around when it is invisible to the user. 更一般而言,避免在用户看不见横幅视图时保持横幅视图。

I remember reading about a hidden property a while back but looking at the iAd Framework Reference , I cannot find any such property. 我记得前一段时间读过有关hidden属性的信息,但在查看《 iAd Framework参考》时 ,我找不到任何此类属性。 I recommend you follow Apple's guidelines if you do not want to display an ad in a specific scene. 如果您不想在特定场景中展示广告,建议您遵循Apple的准则。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM