内容不可用时,iAd会显示白线?

时间:2014-03-01 21:41:18

标签: ios objective-c iad

当没有要显示的内容时,我的广告横幅将替换为白色横幅。基于提供的代码,有什么理由吗?另外,当iAd不可用时,是否还要使用AdMob正确补充横幅?

//iAd Advertising
#pragma mark iAd Delegate Methods

- (void) bannerViewDidLoadAd:(ADBannerView *)banner {

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1];
    [banner setAlpha:1];
    [UIView commitAnimations];

}

- (void) bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1];
    [banner setAlpha:1];
    [UIView commitAnimations];
    advertisement.hidden = YES;


}

我尝试使用Google AdMob进行补充:

#pragma mark iAd Delegate Methods

- (void) bannerViewDidLoadAd:(ADBannerView *)banner {

    advertisement.hidden = NO;
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1];
    [banner setAlpha:1];
    [UIView commitAnimations];
    bannerView_.hidden = YES;

} // if there is an internet connection, load the iAd with a 1 second fade in effect

- (void) bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {

    //MAKE SURE THIS IS RIGHT OR FIGURE OUT HOW TO MAKE IT RIGHT 

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1];
    [banner setAlpha:1];
    [UIView commitAnimations];
    advertisement.hidden = YES; 

    //2
    bannerView_.hidden = NO;
    bannerView_ = [[GADBannerView alloc]initWithFrame:CGRectMake(0, 20, 320, 50)];
    bannerView_.adUnitID = @"//ca-app-pub-";
    bannerView_.rootViewController = self;
    [self.view addSubview:bannerView_];
    [bannerView_ loadRequest:[GADRequest request]];

}

我是错误的做横幅视图的出口并将它们隐藏或显示?它不起作用,它总是只显示其中一个广告,并且如前所述,当iAd不存在时,它只显示一个没有任何内容的白色横幅,这对于应用程序的目的而言是侵入性的而不是装饰性的。

基于此,我做错了什么?对于这两种情况,为什么iAd会显示白色横幅,为什么AdMob不会补充自身。

3 个答案:

答案 0 :(得分:1)

在StoryBoard中,将横幅设置为隐藏。 在您的viewController(定义为横幅的委托)中,输入以下代码:

 - (void)bannerViewDidLoadAd:(ADBannerView *)banner {
    [banner setHidden:false];
}

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
    NSLog(@"Error : %@",error.description);
    [banner setHidden:true];
}

答案 1 :(得分:0)

didFailToReceiveAdWithError:中,您应该将横幅alpha设为零,但实际上您将其设为动画。

答案 2 :(得分:0)

如果在故事板中将alpha设置为0,这将允许您已经习惯使用的代码。有同样的问题。