Question

I am trying to add iads to my new sprite kit game. 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. After that i'm trying to use NSNotification to hide and show the ads in different scenes, but its not working. the ad is still showing even though i've added into Menu.m(scene):

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

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


}
Was it helpful?

Solution

It is not good to create an iAd if you do not intend to show it.

According to Apple's Banner View Best Practices:

• 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. 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. I recommend you follow Apple's guidelines if you do not want to display an ad in a specific scene.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top