I am looking to implement iAd in my app. So far I have managed to get them showing/dismissing correctly in each view using the below.
App Delegate:
import UIKit import iAd @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? var adBannerView = ADBannerView()
View Controller 1:
import UIKit import iAd class HomeScreenViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, ADBannerViewDelegate { let appDelegate = UIApplication.sharedApplication().delegate as AppDelegate //Creates reference to the AppDelegate override func viewDidLoad() { super.viewDidLoad() loadAds() } func loadAds(){ self.appDelegate.adBannerView.removeFromSuperview() self.appDelegate.adBannerView.delegate = nil self.appDelegate.adBannerView = ADBannerView(frame: CGRect.zeroRect) self.appDelegate.adBannerView.center = CGPoint(x: view.bounds.size.width / 2, y: view.bounds.size.height - self.appDelegate.adBannerView.frame.size.height / 2) self.appDelegate.adBannerView.delegate = self self.appDelegate.adBannerView.hidden = true view.addSubview(self.appDelegate.adBannerView) } func bannerViewDidLoadAd(banner: ADBannerView!) { println("bannerViewDidLoadAd") self.appDelegate.adBannerView.hidden = false } func bannerViewActionDidFinish(banner: ADBannerView!) { println("bannerViewActionDidFinish") } func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) { println("didFailToReceiveAdWithError") self.appDelegate.adBannerView.hidden = true }
My goal is to have the same ad displaying in multiple views that the user can switch between. However, it seem's that in practice when you segue from one view to another, ad's stop loading and have to start again. Is there an easier way to pass this adBannerView from one VC to another?
Any help would be appreciated. Thanks!