更改视图后UITabBar iAd Banner未正确加载

时间:2015-07-02 11:57:33

标签: ios iad banner

我有一个UITabBar,在每个视图中都有一个iAd Banner。 第一次选择视图时一切正常,但是当我更改视图而不是返回第一个视图时,iAd横幅无法正确加载(它是白色的,并显示iAd徽标右上角)我收到此错误:The operation couldn’t be completed. Ad was unloaded from this banner

大约15秒后,横幅加载广告

这里是加载横幅的代码(在每个视图中都是相同的)

@property (nonatomic, strong) ADBannerView *banner;

在viewDidLoad

self.banner = [[ADBannerView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height-29-50, self.view.bounds.size.width, 50)];
self.banner.delegate = (id)self;

[self.view addSubview:self.banner];

-(void)bannerViewActionDidFinish:(ADBannerView *)banner{
    NSLog(@"Ad Banner action did finish");
}

-(void)bannerViewDidLoadAd:(ADBannerView *)banner{
    NSLog(@"Ad Banner did load ad.");

    [UIView animateWithDuration:0.5 animations:^{
        self.banner.alpha = 1.0;
    }];
}

-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
    NSLog(@"Unable to show ads. Error: %@", [error localizedDescription]);

    [UIView animateWithDuration:0.5 animations:^{
        self.banner.alpha = 0.0;
    }];
}

1 个答案:

答案 0 :(得分:0)

viewWillAppear中,ADBannerView alpha最初设置为0

-(void)viewWillAppear:(BOOL)animated {
    self.banner.alpha = 0.0;
}

这样,当您重新加载旧view时,您的ADBannerView将被隐藏,直到再次收到来自iAd网络的广告。

更好的方法是在整个应用程序中使用Shared iAd Banner