iAd白色横幅不会消失

时间:2015-01-25 02:09:49

标签: ios iad viewdidload

-(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];
 }

1 个答案:

答案 0 :(得分:1)

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

-(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;
}