Question

I followed the answer on this question How to properly hide these ad banners? to have google AdMob supplement iAd when it is unavailable and it works perfectly, but seldomly the advertisement be it google or apple appears even though I have used the NSNotifcation to tell it not to. I included the NSNotification to hide banners in my initWithSize method on the game scene but sometimes they still appear. I think this has to do with the internet connection and when the request becomes an impression. That being said:

I placed my hideAd notification in the -(void)update:(CFTimeInterval)currentTime method to make sure that the advertisement is hidden. Will this slow down my game though over time?

Is it bad to send an NSNotification with every frame update in a sprite-kit game?

Was it helpful?

Solution

Firstly, you should not be hiding the banner view at all. If you don't want to use it the best thing to do is to destroy it and then recreate it later. From Apple's iAD programming guide:

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.

As far as using NSNotifications per frame that's not a good idea as they have to synchronously notify their listeners with each broadcast. Delegation is better for a case like this but as I said you shouldn't be doing this sort of thing at all, just destroy and recreate it later.

EDIT: Here is the updated code that we were discussing in the comments. You want to create two methods like this on your view controller, but make sure you place the bannerView inside a shell view that has exactly the same frame. So it would look like this:

- (void)hideBanner
{ 
    [self.bannerView removeFromSuperview];
    self.shellView.hidden = YES;
}

- (void)showBanner 
{
    self.bannerView = [[ADBannerView alloc] initWithAdType:type];
    self.shellView.hidden = NO;
    [self.shellView addSubview:self.bannerView];
}

Just make sure the shell view has the same size as the ad banner unit you are trying to display. You COULD set the alpha channel of it to make it transparent but that has performance implications and is unnecessary if you size it correctly.

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