I want to implement iAd in my application. So far, I have managed to display / reject correctly in each view using below.
Application 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
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 show the same ad in multiple views that the user can switch between. However, it seems that in practice, when you move from one glance to another, the ad stops loading and should start again. Is there an easier way to transfer this adBannerView from one VC to another?
Any help would be greatly appreciated. Thank!
source
share