iAd显示白框

时间:2013-12-09 23:18:32

标签: ios7 iad

我对iAd有点问题。有时它会显示一个空白框。当我用Admob尝试它时,它完美无缺。有时横幅从按钮正确显示,但有时会立即显示白框。有什么问题?

这是我的代码:

    -(void)viewDidLayoutSubviews
    {
        if (self.view.frame.size.height != self.iAdBannerView.frame.origin.y)
                    {
            self.iAdBannerView.frame = CGRectMake(0.0, self.view.frame.size.height, self.iAdBannerView.frame.size.width, self.iAdBannerView.frame.size.height);
                                    iAdBannerView.requiredContentSizeIdentifiers= [NSSet setWithObjects: ADBannerContentSizeIdentifierLandscape,nil];
                        iAdBannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
                    }

            if (self.view.frame.size.height != self.gAdBannerView.frame.origin.y)
            {
                self.gAdBannerView.frame = CGRectMake(150, self.view.frame.size.height, self.gAdBannerView.frame.size.width, self.gAdBannerView.frame.size.height);
            }

// Hide the banner by sliding down
-(void)hideBanner:(UIView*)banner
{
    if (banner && ![banner isHidden])
    {
        [UIView beginAnimations:@"hideBanner" context:NULL];
        banner.frame = CGRectOffset(banner.frame, 0, banner.frame.size.height);
        [UIView commitAnimations];
        banner.hidden = TRUE;
    }
}

// Show the banner by sliding up
-(void)showBanner:(UIView*)banner
{
    if (banner && [banner isHidden])
    {
        [UIView beginAnimations:@"showBanner" context:NULL];
        banner.frame = CGRectOffset(banner.frame, 0, -banner.frame.size.height);
        [UIView commitAnimations];
        banner.hidden = FALSE;
    }
}

#pragma mark - ADBanner delegate methods -

// Called before the add is shown, time to move the view
- (void)bannerViewWillLoadAd:(ADBannerView *)banner
{
    NSLog(@"iAd load");
    [self hideBanner:self.gAdBannerView];
    [self showBanner:self.iAdBannerView];
}

// Called when an error occured
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
    NSLog(@"iAd error: %@", error);
    [self hideBanner:self.iAdBannerView];
    [self.gAdBannerView loadRequest:[GADRequest request]];
}

1 个答案:

答案 0 :(得分:0)

iAds并不总是加载广告。有一种委托方法可以让您知道广告成功加载的时间。

ADBannerViewDelegatebannerViewDidLoadAd:bannerView:didFailToReceiveAdWithError: