iAds不适用于模拟器和设备

时间:2011-11-24 09:42:18

标签: iphone objective-c

当我运行我的应用程序时,我收到了iAd横幅视图的此消息。这是什么意思?

  

错误Domain = ADErrorDomain Code = 3“操作无法执行   完成。广告资源不可用“UserInfo = 0x60455a0   {ADInternalErrorCode = 3,NSLocalizedFailureReason =广告资源   不可用}

这是我的代码:

#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 

3 个答案:

答案 0 :(得分:2)

您将在模拟器或设备中随机收到此错误消息,以便在没有iAd可用时测试您的应用及其行为(隐藏AdView,使用其他广告提供商...)。但它不是来自Simulator / iAd framework / iAd网络的错误:它是一个可以进行更好测试的功能。

此外,在测试设备上以测试模式部署应用时,您无法获得“真正的”iAd。它必须由Apple审核并从AppStore下载。

答案 1 :(得分:0)

“广告资源不可用”表示...没有广告可用。它看起来好像工作正常。

iAd易于实施,但填充率较低(即许多请求未实现),并且在许多国家/地区根本无法使用。

答案 2 :(得分:0)

从您的设备中删除该应用,然后从XCode重新安装。这为我解决了。