I've been scratching my head about this for a couple of days. I can't get iAds to show up in the simulator (or real hardware).
I can't figure out why the test ads aren't loading. Has anybody else had this problem? As I understand it you no longer have to register each app individually for iAds through iTunes Connect anymore.
I'll include my code below for reference, though I have a suspicion that the problem is somewhere in the setup.
import UIKit
import iAd
class AdViewController: UIViewController, ADBannerViewDelegate {
var bannerView = ADBannerView()
override func viewDidLoad() {
super.viewDidLoad()
self.canDisplayBannerAds = true
bannerView.frame = CGRectMake(0, self.view.frame.height-50, self.view.frame.width, 50)
view.addSubview(bannerView)
bannerView.delegate = self
bannerView.hidden = true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func bannerViewDidLoadAd(banner: ADBannerView!) {
self.bannerView.hidden = false
println("bannerView unhidden")
}
func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
bannerView.hidden = true
println("bannerView hidden")
}
func bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) -> Bool {
return willLeave
}
}
Edit: This morning I tried downloading and running some iAd demos from gitHub just to see if I could get them to work, but to no avail. I assume the code is correct, so something must be wrong elsewhere. https://github.com/sarchak/iAds
it is not recommend to manually set the size of an ad view.
use init()
method and then adjust the frame doesn't make any sense
you should initialize your banner view like this:
let bannerView = ADBannerView(adType:ADAdType.Banner)
and then immediately set its delegate and add it to the root view