I have an iAd banner that I created in my storyboard and I have added these four constraints: (height: 50, width: 320, horizontal center in container, and 10 from top portion of view). Sometimes when I run the app the iAd banner is positioned right where I placed it, other times it just randomly appears across the bottom of the screen. My app is restricted to landscape only if that has something to do with it. What am I doing wrong?
import UIKit
import AVFoundation
import iAd
class ViewController: UIViewController, ADBannerViewDelegate {
@IBOutlet weak var adBanner: ADBannerView!
override func viewDidLoad() {
super.viewDidLoad()
// Set ad banner settings
self.canDisplayBannerAds = true
self.adBanner?.delegate = self
self.adBanner?.hidden = true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func bannerViewWillLoadAd(banner: ADBannerView!) {
self.adBanner?.hidden = true
}
func bannerViewDidLoadAd(banner: ADBannerView!) {
self.adBanner?.hidden = false
}
func bannerViewActionDidFinish(banner: ADBannerView!) {
}
func bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) -> Bool {
return true
}
func bannerView(banner: ADBannerView!, didFailToRecieveAdWithError error: NSError!) {
self.adBanner?.hidden = true
}
}
self.canDisplayBannerAds = true
is creating the banner that's appearing on the bottom of the screen. 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. You need to remove self.canDisplayBannerAds = true
from your viewDidLoad()
. When you create an ADBannerView
in your storyboard this is not necessary.