Search code examples
swiftiad

Swift iOS: iAd not populating


I'm building an iPhone app with swift, and I've got a Rectangular Banner ad I'm trying to show. I've gotten my Dev account properly set up for iAds, but the ad doesn't populate in the app. I get a test ad, but not where I expect it.

Here's the code for the controller with the ad, and a screenshot:

//
//  AdViewController.swift
//
//  Created by Kevin Whitaker on 3/26/15.
//

import UIKit
import iAd

class AdViewController: UIViewController, ADBannerViewDelegate {

    @IBOutlet weak var AdView: ADBannerView!

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        self.canDisplayBannerAds = true
        AdView = ADBannerView(adType: ADAdType.MediumRectangle)
        AdView?.delegate = self
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    override func prefersStatusBarHidden() -> Bool {
        return true
    }

    override func shouldAutorotate() -> Bool {
        return false
    }

    // MARK: - Ads
    func bannerViewDidLoadAd(banner: ADBannerView!) {
        self.view.addSubview(banner)
    }

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

}

Screenshot of the blank ad


Solution

  • As @KnightOfDragon mentioned in the comments, the medium rectangle ad is only available for applications running on iPad. What you're looking for is an interstitial ad. These are the full screen ads you see in other iPhone apps.