w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Swift - ADBannerView

I've found a solution, how to implement it. (You can use inside each method "banner.alpha 1.0" or other things, too.)

//import ... your normal imports as UIKit etc.
import iAd

class YourClassViewController: UIViewController, ADBannerViewDelegate {

   @IBOutlet var adBannerView: ADBannerView //connect in IB connection
inspector with your ADBannerView

   override func viewDidLoad() {

      self.canDisplayBannerAds = true
      self.adBannerView.delegate = self
      self.adBannerView.hidden = true //hide until ad loaded

   func bannerViewWillLoadAd(banner: ADBannerView!) {

   func bannerViewDidLoadAd(banner: ADBannerView!) {
      self.adBannerView.hidden = false //now show banner as ad is loaded

   func bannerViewActionDidFinish(banner: ADBannerView!) {

      //optional resume paused game code


   func bannerViewActionShouldBegin(banner: ADBannerView!,
willLeaveApplication willLeave: Bool) -> Bool {

      //optional pause game code

      return true

   func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError
error: NSError!) {

   //... your class implementation code


See the following answer, on how to do it without IBBuilder!

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.