Search code examples
swiftios-simulatoriad

didFailToReceiveAdWithError function of iad is not working


I implemented both iAd and AdMob to my project. The structure is if an error comes from iAd server, the app going to show Admob banner or interstitial according to error ad type. Interstitial works fine. But not banners. I used the function shown below and I selected the iAd fill rate to 0% in developer setting of simulator. But it's not writing "WORKED" to console and it's not showing iAd Banner ad(as expected). How can I solve this problem?

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

    }

Solution

  • You're probably not setting your ADBannerView's delegate properly. Your code should look similar to this:

    class ViewController: UIViewController, ADBannerViewDelegate { // Include the delegate for our ADBannerView
    

    And then wherever you are setting up your ADBannerView you need to set its delegate. For example:

    yourAdBannerView.delegate = self
    

    You will probably want to print your error also so you know why it has failed. For example:

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