iAd ADBannerView detect unloading

牧云@^-^@ 提交于 2019-12-23 03:18:07

问题


If you add an ADBannerView you can detect when it loads an AD from its delegate function:

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

This can be helpful if you have views below the banner that you need to move or resize when the banner loads.

I coudn't find any way to detect when the banner is disappearing to move back again all the views in place.

The delegate has only these functions:

Detecting When Advertisements Are Loaded

– bannerViewWillLoadAd:
– bannerViewDidLoadAd:

Detecting When a User Interacts With an Advertisement

– bannerViewActionShouldBegin:willLeaveApplication:
– bannerViewActionDidFinish:

Detecting Errors

– bannerView:didFailToReceiveAdWithError:

Nothings seems to get triggered when the banner unloads.

Any way to detect the banner unload or any workarounds? Thanks!


回答1:


I use bannerViewDidLoadAd when a banner is load and so show this banner with an animation

#pragma mark - ADBannerViewDelegate
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
    NSLog(@"banner loaded");

    // Display BannerView
    _iAdBannerView.hidden = NO;
    [UIView animateWithDuration:0.4f
                     animations:^{
                         _iAdBannerView.alpha = 1.0f;
                     }];
}

And I use didFailToReceiveAdWithError when the banner is unload (so here, you can add an animation to move your view for example) :

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
    // Print error
    NSLog(@"error banner failed :\n%@", error);

    // Hide BannerView
    [UIView animateWithDuration:0.4f
                     animations:^{
                         _iAdBannerView.alpha = 0.0f;
                     } completion:^(BOOL finished) {
                         _iAdBannerView.hidden = YES;
                     }];
}


来源:https://stackoverflow.com/questions/19097544/iad-adbannerview-detect-unloading

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!