Swift – ADBannerView

Hi guys I tryed to implement ADBannerView with the old way like Objective C but unsuccessfull. Everythings work but the advertisments didn’t show up, it stays a blank field.

func bannerViewDidLoadAd(banner: ADBannerView!) {
    UIView.beginAnimations(nil, context: nil)
    UIView.setAnimationDuration(1)
    banner.alpha = 1
    UIView.commitAnimations()
}

func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
    UIView.beginAnimations(nil, context: nil)
    UIView.setAnimationDuration(1)
    banner.alpha = 0
    UIView.commitAnimations()
}

Anyone who already tryed iAd on Swift ?

ADBannerView contents

Is there any way of knowing which ad loaded in an ADBannerView, or in any way control the ad that loads?

ADBannerView memory management

Is an AdBannerView released when its action has finished?



AdBannerView removeFromSuperview

I am trying to remove a AddBannerView that has been created in a Storyboard and referenced in the UIViewController in this way: @property (nonatomic,weak) IBOutlet ADBannerView *banner; The problem

getting ADBannerView error message

I am creating ADBannerView in my iPhone application programmatically, can anybody say me that, why I am geeting this message in my console, ADBannerView: Unhandled error (no delegate or delegate does

iAd ADBannerView detect unloading

If you add an ADBannerView you can detect when it loads an AD from its delegate function: – (void)bannerViewDidLoadAd:(ADBannerView *)banner { This can be helpful if you have views below the banner t

Preventing UIPopoverController from covering ADBannerView

I have PhotoViewController that contains OverlayView and ADBannerView. OverlayView has some buttons which display UIPopoverControllers. Sometimes this popovers display over ADBannerView and I get a wa

how to implement AdBannerview and ADBannerview delegate

I am having trouble implementing ADBannerView and its delegate protocol. I implemented the following code in my view class (also made the view conform to the ADBannerViewDelegate protocol): //add iAd

ADBannerView Warning Message

I am using AdBannerView and I see the following message in the Application Output window while debugging my app. ADBannerView: WARNING A banner view (0x98c0c40) has an ad but may be obscured. This me

How to use ADBannerView?

i just added a ADBannerView to my view using interface builder. There was no errors or warnings when i tried build and run. But when i reached the page containing ad banner the application crashed. Re

AdBannerView weird color overlay

I added AdBannerView to my storyboard and it has a weird color overlay (usually green but sometimes red or yellow). It happens on simulator and real device as well. Screenshots: http://postimg.org/ima

Answers

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() {
      super.viewDidLoad()

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

   func bannerViewWillLoadAd(banner: ADBannerView!) {
      NSLog("bannerViewWillLoadAd")
   }

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

   func bannerViewActionDidFinish(banner: ADBannerView!) {
      NSLog("bannerViewDidLoadAd")

      //optional resume paused game code

   }

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

      //optional pause game code

      return true
   }

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

   //... your class implementation code

}

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

Mr. T answer contains a lot of useless code.

All you need is this part to show ads in your controller:

override func viewDidLoad() {
      super.viewDidLoad()

      canDisplayBannerAds = true
}

And when you don’t need ads, you canDisplayBannerAds = false.

What this command does — it wraps your controller into another controller with ad banner. This feature is available since iOS7.

If you are using iOS 7, extension methods and properties have been added to UIViewController to support handling of iAd:

See

https://developer.apple.com/library/prerelease/ios/documentation/iAd/Reference/UIViewController_iAd_Additions/index.html

To show an iAd you first need to add the iAd framework, go to the projects properties, general tab, add the iAd.framework in the Linked framework and libraries section.

In your view controller, import iAd to access the iAd extensions. And finally in viewDidLoad, set self.canDisplayBannerAds = true.

To remove ads, set canDisplayBannerAds to false

Note there is no need to create an AdBannerView in the story board or programmatically and there is no need for your view controller to implement the AdViewDelegate.

import UIKit
import iAd

class ViewController : UIViewController
{
    override func viewDidLoad()
    {
        super.viewDidLoad()
        //That's it
        self.canDisplayBannerAds = true
    }
}