Search code examples
xcodeswiftiad

iAd Swift 2 ads displaying on screen


I am new to iAd and I have an problem because my view displays 2 ad banners and I have no idea why.

This is my code:

var bannerView: ADBannerView!
bannerView = ADBannerView(adType: .Banner)
bannerView.setTranslatesAutoresizingMaskIntoConstraints(false)
bannerView.delegate = self
bannerView.frame = CGRectMake(0, 63, 320, 50)
canDisplayBannerAds = true
view.addSubview(bannerView)

The first time I load the view there is just one Ad. If I reload the view several times it displays one ad at the bottom and one at the top of the screen.

I made some researches and it seems like I am generating several ads. But why?


Solution

  • You are actually making two ads. The one you defined the frame for and the one that self.canDisplayBannerAds = true. The canDisplay method is used when you don't want to have to manipulate the ads. This method places the ad at the bottom. Take that out and it should work fine.