Why doesn't my iAd banner appear when theres an error loading my FB Audience Network banner ad?

| | August 18, 2015

I have iAds and Facebook’s Audience Network as my two banner ads. When there is an error loading my Audience Network’s banner ad I want my iAd banner to appear. When I try to call it in this function my iAd banner does not appear. I’m testing this on my device and have set the developers settings fill rate to 0%. My Audience Network’s banner ad still shows when I do this. What am I doing wrong?

class GameViewController: UIViewController, ADBannerViewDelegate,
        ADInterstitialAdDelegate, SKProductsRequestDelegate,
    SKPaymentTransactionObserver, ChartboostDelegate, FBAdViewDelegate {

    var productID: NSString!
    let defaults = NSUserDefaults.standardUserDefaults()

    override func viewDidLoad() {
        if let scene = GameScene.unarchiveFromFile("GameScene") as? GameScene {
            // Configure the view.
            let skView = self.view as! SKView
            skView.showsFPS = false
            skView.showsNodeCount = false
            skView.multipleTouchEnabled = true

            /* Sprite Kit applies additional optimizations to improve rendering performance */
            skView.ignoresSiblingOrder = true

            /* Set the scale mode to scale to fit the window */
            scene.scaleMode = SKSceneScaleMode.AspectFill
            //scene.size = skView.bounds.size

        func loadFbAds() {
            if defaults.boolForKey("removeAdsPurchased") == false {
                let width = self.view.frame.size.width
                let height = self.view.frame.size.height / 10

                let adView: FBAdView = FBAdView(placementID:"placement_id", adSize:kFBAdSize320x50, rootViewController:self)
                adView.frame = CGRect(x: 0, y: self.view.frame.size.height - 50, width: width, height: height)

                adView.delegate = self


        func adView(adView: FBAdView!, didFailWithError error: NSError!) {
            adBannerView = ADBannerView(frame: CGRect.zeroRect)
            adBannerView.center = CGPoint(x: adBannerView.center.x, y: view.bounds.size.height - adBannerView.frame.size.height / 2)
            adBannerView.delegate = self
            adBannerView.hidden = false

            adView.hidden = true

One Response to “Why doesn't my iAd banner appear when theres an error loading my FB Audience Network banner ad?”

  1. The fill rate in your developer settings refers to your iAd fill rate only. Set this to 100%. You should be creating your iAd ADBannerView and FB FBAdView globally and setting them up once your view loads in your viewDidLoad. Then, when your FB FBAdView fails to load you can just set your ADBannerView‘s hidden property to false. The way you have it setup now you will be creating a new iAd ADBannerView each time your FB FBAdView fails to load an ad. Your code should end up looking very similar to this:

        // Create our FB and iAd banners globally
        var fbBannerAd: FBAdView = FBAdView()
        var iAdBannerAd: ADBannerView = ADBannerView()
    override func viewDidLoad() {
        // View loaded so lets setup our ads
    func setupAds() {
        // FB
        // Create FB banner ad with our placementID and select an adSize
        fbBannerAd = FBAdView(placementID:"placementID", adSize:kFBAdSizeHeight50Banner, rootViewController:self)
        // Set its frame relative to the screen
        fbBannerAd.frame = CGRect(x: 0, y: self.view.frame.size.height - fbBannerAd.frame.height, width: self.view.frame.size.width, height: fbBannerAd.frame.height)
        // Request ad from FB
        // Set our ads delegate to 'self'
        fbBannerAd.delegate = self
        // Add our FB ad to our view
        // iAd
        // Set its frame relative to the screen
        iAdBannerAd.frame = CGRect(x: 0, y: self.view.frame.size.height - iAdBannerAd.frame.height, width: self.view.frame.size.width, height: iAdBannerAd.frame.height)
        // Set our ads delegate to 'self'
        iAdBannerAd.delegate = self
        // Add our iAd ad to our view
        // Lets hide our iAd ad initially
        iAdBannerAd.hidden = true
        println("created our banner ads")
    func adView(adView: FBAdView!, didFailWithError error: NSError!) {
        // FB ad failed to load
        // Lets print the error so we know why
        println("failed to load fb ad with error: (error)")
        // Also lets hide our FB ad because it doesn't have an ad to show
        fbBannerAd.hidden = true
        // And now we show our iAd ad
        iAdBannerAd.hidden = false
    func adViewDidLoad(adView: FBAdView!) {
        // FB ad loaded an ad
        // Lets make sure it is shown and our iAd ad is hidden
        fbBannerAd.hidden = false
        iAdBannerAd.hidden = true

    Then, to see what happens when your FB FBAdView fails you can call:

    adView(fbBannerAd, didFailWithError: nil)

Leave a Reply