I'm using the MoPub banner ad, I added the following code to my View Controller's viewDidLoad:
self.adView.delegate = self
self.adView.frame = CGRectMake(0, self.view.bounds.size.height - MOPUB_BANNER_SIZE.height,
MOPUB_BANNER_SIZE.width, MOPUB_BANNER_SIZE.height)
self.view.addSubview(self.adView)
self.adView.loadAd()
But it makes the ad visible in all the scenes when I only want it to be visible in the main menu scene.
How do I remove the ad in the scenes that I don't want it to be?
This might not be the best way to do this, but it is probably the simplest. You could use an
NSNotificationto broadcast a message to yourViewControllerwhenever you wish to show or hide you banner.For instance if you add an "observer" in your
ViewControlleroninitorviewDidLoad:To make the
ViewControllerlisten for a message called"hideAd"and then execute a method calledhideBannerAd.Then implement this method:
Be sure to remove the observer on
deinit, this isn't likely to be an issue what with the persistance of aViewControllerinSpriteKitbut it's good practice.Then, when you want to show or hide the view, for example on a scene transition or game over method, you can implement this
hideBannerAdmethod by triggering the observer using:And the banner should hide. This can then be repeated for a similar
showBannerAdmethod by setting thehiddenproperty tofalse, or you can have a single method that simply toggles the hidden property usingadView.hidden = !adView.hidden.I hope this helps.