13

I'm getting didFailToReceiveAdWithError message in the console while running on the simulator and device.

iAd banners are displayed successfully when running on iOS 8. When running on iOS 9, iAd banners fail to receive an ad.

.h

#import <iAd/iAd.h>
@interface ViewController : UIViewController <ADBannerViewDelegate>

@property (retain, nonatomic) IBOutlet ADBannerView *adBanner;

.m

-(void)viewDidLoad {
    self.adBanner = [[ADBannerView alloc]initWithFrame:CGRectMake(0,[UIScreen mainScreen].bounds.size.height-100, [UIScreen mainScreen].bounds.size.width, 50)];
    self.adBanner.delegate=self;
    [self.adBanner setBackgroundColor:[UIColor clearColor]];
    [self.view addSubview:self.adBanner];
}   

-(void)bannerViewWillLoadAd:(ADBannerView *)banner {
    NSLog(@"bannerViewWillLoadAd");
}

-(void)bannerViewDidLoadAd:(ADBannerView *)banner {
    // Show the ad banner.
    NSLog(@"bannerViewDidLoadAd");

    [UIView animateWithDuration:0.5 animations:^{
        self.adBanner.alpha = 1.0;
    }];
}

-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
    NSLog(@"didFailToReceiveAdWithError");

    // Hide the ad banner.
    [UIView animateWithDuration:0.5 animations:^{
        self.adBanner.alpha = 0.0;
    }];
}    

-(void)bannerViewActionDidFinish:(ADBannerView *)banner {
    NSLog(@"Ad did finish");
}

When running on iOS 9, the console prints didFailToReceiveAdWithError every time.

Daniel Storm
  • 18,301
  • 9
  • 84
  • 152
Rohit suvagiya
  • 1,005
  • 2
  • 12
  • 40
  • 1
    I've copy pasted your code in a new xcode 7 project with iOS 9.1 It is working. – Warif Akhand Rishi Dec 21 '15 at 11:35
  • Based on your code, I think that the IBOutlet is necessary, only the declarion of variable in the interface. It is not needed to draw the banner in the Interface Builder. Setting the backgroundcolor of the Ad is not allowed. (Just followed the anser of Daniel Storm, works great for me.) – Vincent Mar 19 '16 at 11:22

3 Answers3

6

I'm unable to recreate your issue. The iAd network may have been down for your country when testing this, you may be in a country that iAd does not support, or it may be that you've set your iAd Testing Fill Rate to 0% on your development device/simulator. Go to Settings>Developer>Fill Rate> and check that Fill Rate is set to 100% on your development device/simulator.

I'd suggest printing the error you're receiving in didFailToReceiveAdWithError so you can find out why the ADBannerView is failing.

-(void)viewDidLoad {
    // The ADBannerView will size itself based on the device it is being displayed on
    // Only setting the position is sufficient
    self.adBanner = [[ADBannerView alloc]initWithFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height-100, 0, 0)];
    self.adBanner.delegate=self;
    // Removed setBackgroundColor
    // Set alpha to 0.0 initially
    self.adBanner.alpha = 0.0;
    [self.view addSubview:self.adBanner];
}

-(void)bannerViewWillLoadAd:(ADBannerView *)banner {
    NSLog(@"bannerViewWillLoadAd");
}

-(void)bannerViewDidLoadAd:(ADBannerView *)banner {
    NSLog(@"bannerViewDidLoadAd");
    [UIView animateWithDuration:0.5 animations:^{
        self.adBanner.alpha = 1.0;
    }];
}

-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
    // Changed NSLog to print the error that is received
    NSLog(@"didFailToReceiveAdWithError: %@", error);
    [UIView animateWithDuration:0.5 animations:^{
        self.adBanner.alpha = 0.0;
    }];
}

-(void)bannerViewActionDidFinish:(ADBannerView *)banner{
    NSLog(@"bannerViewActionDidFinish");
}

If you're still having this issue you should contact iAd directly and update your question based on their response, or post an answer if they're able to solve it for you.

Daniel Storm
  • 18,301
  • 9
  • 84
  • 152
  • @sohil which country are you in? – Daniel Storm Dec 25 '15 at 12:15
  • @sohil read the beginning of my answer. While India is an iAd supported country, iAd may be having issues with delivering ads to India at the moment. I can confirm this and the OP's code works as expected in the US. [Contact iAd](https://itunesconnect.apple.com/WebObjects/iTunesConnect.woa/wa/jumpTo?page=contactUs) directly and see if you're able to get a solution from them. – Daniel Storm Dec 25 '15 at 12:37
1

Try adding app transport security in your project's plist file. enter image description here

greg-449
  • 109,219
  • 232
  • 102
  • 145
0

I found this here :

Checking my storyboard I noticed, that a height constraint for 32 was set for the ADBannerView - the 32 was not a valid height in that orientation. Removing that height constraint removed the error "Ad inventory unavailable" and it worked beautifully from then on.

Check if that works for you.

Also check with the iAD Changelog to see if there's anything you might need to worry about.

ShahiM
  • 3,179
  • 1
  • 33
  • 58