Rocky
Rocky

Reputation: 1423

iAds not working in Simulator and device

When I run my application I get this message for iAd banner view. What does it mean?

Error Domain=ADErrorDomain Code=3 "The operation couldn’t be completed. Ad inventory unavailable" UserInfo=0x60455a0 {ADInternalErrorCode=3, NSLocalizedFailureReason=Ad inventory unavailable}

This is my code:

#pragma mark -
#pragma mark create BannerView:
- (void)createAdBannerView {
    Class classAdBannerView = NSClassFromString(@"ADBannerView");
    if (classAdBannerView != nil) {
        self.adBannerView = [[[classAdBannerView alloc] initWithFrame:CGRectZero] autorelease];
        [adBannerView setRequiredContentSizeIdentifiers:[NSSet setWithObjects: ADBannerContentSizeIdentifierPortrait, ADBannerContentSizeIdentifierLandscape, nil]];
        if (UIInterfaceOrientationIsLandscape([UIDevice currentDevice].orientation)) {
            [adBannerView setCurrentContentSizeIdentifier:ADBannerContentSizeIdentifierLandscape];
        } else {
            [adBannerView setCurrentContentSizeIdentifier:ADBannerContentSizeIdentifierPortrait];            
        }
        [adBannerView setFrame:CGRectOffset([adBannerView frame], 0, -[self getBannerHeight])];
        [adBannerView setDelegate:self];

        [self.view addSubview:adBannerView];        
    }
}

- (void)fixupAdView:(UIInterfaceOrientation)toInterfaceOrientation {
    if (adBannerView != nil) {        
        if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {
            [adBannerView setCurrentContentSizeIdentifier:ADBannerContentSizeIdentifierLandscape];
        } else {
            [adBannerView setCurrentContentSizeIdentifier:ADBannerContentSizeIdentifierPortrait];
        }          
        [UIView beginAnimations:@"fixupViews" context:nil];
        if (adBannerViewIsVisible) {
            CGRect adBannerViewFrame = [adBannerView frame];
            adBannerViewFrame.origin.x = 0;
            adBannerViewFrame.origin.y = 0;
            [adBannerView setFrame:adBannerViewFrame];
            CGRect contentViewFrame = contentView.frame;
            contentViewFrame.origin.y = [self getBannerHeight:toInterfaceOrientation];
            contentViewFrame.size.height = self.view.frame.size.height - [self getBannerHeight:toInterfaceOrientation];
            contentView.frame = contentViewFrame;
        } else {
            CGRect adBannerViewFrame = [adBannerView frame];
            adBannerViewFrame.origin.x = 0;
            adBannerViewFrame.origin.y = -[self getBannerHeight:toInterfaceOrientation];
            [adBannerView setFrame:adBannerViewFrame];
            CGRect contentViewFrame = contentView.frame;
            contentViewFrame.origin.y = 0;
            contentViewFrame.size.height = self.view.frame.size.height;
            contentView.frame = contentViewFrame;            
        }
        [UIView commitAnimations];
    }   
}





#pragma mark -
#pragma mark ADBannerViewDelegate

- (void)bannerViewDidLoadAd:(ADBannerView *)banner {
    if (!adBannerViewIsVisible) {                
        adBannerViewIsVisible = YES;
        [self fixupAdView:[UIDevice currentDevice].orientation];
    }
}

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
    NSLog(@"the failed error is %@",error); 
    if (adBannerViewIsVisible)
    {        
        adBannerViewIsVisible = NO;
        [self fixupAdView:[UIDevice currentDevice].orientation];
    }
    //NSLog(@"bannerView:didFailToReceiveAdWithError: %@",[error localizedDescription]);

}


how to solve this problem 

Upvotes: 1

Views: 2079

Answers (3)

Francois
Francois

Reputation: 10968

You will randomly get this error message in Simulator or device, so that you can test your app and its behavior when no iAd is available (hidding the AdView, using another ad provider...). But it's not a bug from Simulator / iAd framework / iAd network: it's a feature to make better tests.

Moreover, you cannot get "real" iAds when deploying your app in test mode on test device. It has to be reviewed by Apple and downloaded from the AppStore.

Upvotes: 2

John Goering
John Goering

Reputation: 39030

Delete the app from your device and reinstall from XCode. That fixed it for me.

Upvotes: 0

Stephen Darlington
Stephen Darlington

Reputation: 52565

"Ad inventory unavailable" means... there is no ad available. It looks as though it's working correctly.

iAd is easy to implement but they have low fill rates (i.e., many requests go unfulfilled) and it's not available at all in many countries.

Upvotes: 0

Related Questions