Reputation: 1664
I have an AdBannerView inside my game, but it keeps showing randomly even though I set it to hidden, it pops from the bottom pushing the view up.
Here's the code I have thus far in GameScene:
var iAd = ADBannerView()
override func didMoveToView(view: SKView) {
iAd.delegate = self
iAd.hidden = true
iAd.autoresizingMask = UIViewAutoresizing.FlexibleTopMargin
view.addSubview(iAd)
}
func bannerViewDidLoadAd(banner: ADBannerView!) {
if (!isStarted){ // <- If game has started
iAd.hidden = false
}
}
func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
print("Ad Fail")
iAd.hidden = true
}
func newGame() {
iAd.hidden = true
}
func gameOver() {
iAd.hidden = false
}
Sometimes the ad shows during gameplay, sometimes it shows at the top, other times at the bottom.
My questions are:
MORE INFO: I tried this code in ViewController, but ended up with the same results.
Upvotes: 2
Views: 111
Reputation: 18908
Sounds like you've created an ADBannerView
in Interface Builder in addition to including self.canDisplayBannerAds
somewhere in your project.
The ADBannerView
displaying on the bottom of your devices screen is created by self.canDisplayBannerAds = true
. self.canDisplayBannerAds = true
can be used for a no hassle way of implementing iAd banners in your application. This will create an ADBannerView
for you and show or hide the ADBannerView
depending on whether it receives an ad or not from the iAd network.
If you have included self.canDisplayBannerAds = true
in your project you need to remove it.
As for hiding the ADBannerView
when it fails to receive an advertisement, you need to implement the ADBannerView
's delegate methods: ADBannerViewDelegate Protocol Reference. Then, in bannerView(_:didFailToReceiveAdWithError:)
you'd set your ADBannerView
's alpha
property to 0
.
Upvotes: 1
Reputation: 5461
For question 1: You have set the frame property to position the banner ad:
iAd.frame = CGRectMake(0, view.frame.size.height - iAd.frame.size.height, view.frame.size.width, iAd.frame.size.height);
Upvotes: 1