Thank you pbush25, I found the solution. I post it if others need it.
In appDelegate.swift
class AppDelegate: UIResponder, UIApplicationDelegate, ADBannerViewDelegate {
var window: UIWindow?
var adBannerView = ADBannerView()
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
adBannerView.delegate = self
adBannerView.hidden = true
return true
}
func bannerViewDidLoadAd(banner: ADBannerView!) {
print("bannerViewDidLoadAd")
adBannerView.hidden = false
}
func bannerViewActionDidFinish(banner: ADBannerView!) {
print("bannerViewActionDidFinish")
}
func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
print("didFailToReceiveAdWithError: \(error)")
adBannerView.hidden = true
}
func bannerViewWillLoadAd(banner: ADBannerView!) {
print("bannerViewWillLoadAd")
}
func bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) -> Bool {
print("bannerViewActionShouldBegin")
return true
}
and in every view I want to show iAd
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
override func viewDidLoad() {
super.viewDidLoad()
self.defaultLoad()
}
override func viewWillAppear(animated: Bool) {
self.defaultLoad()
}
override func viewWillDisappear(animated: Bool) {
appDelegate.adBannerView.delegate = nil
view.removeFromSuperview()
}
func defaultLoad(){
appDelegate.adBannerView.frame = CGRectMake(0, (view.frame.height) - 99, (view.frame.size.width), 50) // 50(banner)+49(tab bar)
appDelegate.adBannerView.delegate = appDelegate
super.view.addSubview(appDelegate.adBannerView)
super.view.bringSubviewToFront(appDelegate.adBannerView)
super.view.layoutIfNeeded()
super.canDisplayBannerAds = true
}