-(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,因为它也没有空格?

-(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。同样,在bannerView中对didFailToReceiveAdWithError:的任何提及都应为self.bannerViewbanner,例如:

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

关于ios - iAd白色横幅不会消失,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28132503/

10-13 05:05