iAd 白色横幅不会消失

iAd white banner won't go away

-(void)viewDidLoad{

    self.bannerView = [[ADBannerView alloc] initWithFrame:CGRectMake(0.0f, 60.0f, 320.0f, 50.0f)];
    [self.bannerView setDelegate:self];
    [self.view addSubview:self.bannerView]; 
}


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

    [bannerView setDelegate:self];
    [bannerView setAlpha:0];
    bannerView.hidden=YES;
}

一旦 viewDidLoad 加载并且在 iAd 加载之前,总是在 iAd 横幅出现之前有一个白色的空白填充横幅。我没有在情节提要中设置 AdBannerView。我该怎么做才能确定是否没有 iAd,因为它的位置也没有白色 space?

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

  admobBannerView=[[GADBannerView alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];

self.admobBannerView.adUnitID = @"UNIT-ID";
self.admobBannerView.rootViewController = self;
self.admobBannerView.delegate = self;

[self.view addSubview:self.admobBannerView];

GADRequest *request =[GADRequest request];

request.testDevices= @[ GAD_SIMULATOR_ID ]; 

[self.admobBannerView loadRequest:request];
 }

在创建广告时隐藏广告视图,因为第一个广告加载或失败需要时间,例如:

-(void)viewDidLoad {

    self.bannerView = [[ADBannerView alloc] initWithFrame:CGRectMake(0.0f, 60.0f, 320.0f, 50.0f)];
    [self.bannerView setDelegate:self];
    self.bannerView.hidden = YES; <-- Hide it
    [self.view addSubview:self.bannerView]; 
}

然后在广告加载后重新出现,例如:

- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
    self.bannerView.hidden = NO;
}

至于当前在您的 didFailToReceiveAdWithError: 方法中的代码,您不需要将 alpha 设置为 0 或再次将委托设置为 self。此外,在 didFailToReceiveAdWithError: 中提及 bannerView 应该是 self.bannerViewbanner,例如:

-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
    self.bannerView.hidden=YES;
}