ios - 我隐藏了我的 AdBannerView 但仍然收到警告横幅 View (0x9c75550) 有广告

标签 ios modal-dialog adbannerview

我刚刚在我的应用程序中添加了一个 ADBannerview。我在我的 UIApplicationDelegate 中创建了 AdBannerView,以便只有它的一个实例,并在不同的 viewController 中共享它

一切正常,除了我收到警告消息:ADBannerView:警告横幅 View (0x9c75550) 有广告但可能被遮挡。每个横幅 View 仅打印一次此消息。

当我在当前显示 ADBannerview 的 View 之上打开模态视图(使用 presentModalViewController)时。在打开模态视图之前,我使用以下代码来隐藏 ADBannerview:

- (void)viewWillDisappear:(BOOL)animated
{
    ADBannerView *bannerView = [ (ScoreBoardAppDelegate*)[[UIApplication sharedApplication] delegate] adBanner];
    [self hideBanner:bannerView];
    [super viewWillDisappear:animated];
}

- (void)hideBanner:(ADBannerView*) adBanner {
    NSLog(@"%s called", __FUNCTION__);

    // Grow the tableview to occupy space left by banner, it's the size of the parent view
    CGFloat fullViewHeight = self.tbView.frame.size.height;
    CGRect tableFrame = self.tv.frame;
    tableFrame.size.height = fullViewHeight;

    // Move the banner view offscreen
    CGRect bannerFrame = adBanner.frame;

    CGRect screenBounds = [[UIScreen mainScreen] bounds];
    bannerFrame.origin = CGPointMake(CGRectGetMinX(screenBounds), CGRectGetMaxY(screenBounds));

    self.tv.frame = tableFrame;
    adBanner.frame = bannerFrame;
}

我不明白该怎么做才能没有这个警告信息。在显示模态视图之前,ADBannerView 似乎已成功隐藏(屏幕外)。

我可能错过了什么,但我看不到。 感谢您的帮助,

塞巴斯蒂安。

最佳答案

Sébastien,我希望你已经离开了这个问题,因为这个问题已经好几个月没有得到解答了。我最近添加了 iAd 支持,发现这个警告也很烦人。共享广告横幅的一个微妙之处在于,如果你想在你的初始 View Controller 中显示它,你必须在该 View Controller 中完成大部分设置,而不是在应用程序委托(delegate)中。

这是我初始 View Controller 中的 viewWillAppear: 方法:

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    if (!SharedAdBannerView) {
        // in my app, the ad banner is the bottom-most thing on screen
        CGRect startingFrame = CGRectMake(0.0, self.view.frame.origin.y + self.view.frame.size.height, 320.0, 50.0);
        adBanner = [[ADBannerView alloc] initWithFrame:startingFrame];

        // Set the autoresizing mask so that the banner is pinned to the bottom
        adBanner.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin;

        // Since we support all orientations, support portrait and landscape content sizes.
        // If you only supported landscape or portrait, you could remove the other from this set
        adBanner.requiredContentSizeIdentifiers = [NSSet setWithObjects:ADBannerContentSizeIdentifierPortrait, nil];
        adBanner.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;

        adBanner.delegate = self;
        [self.view addSubview:adBanner];
        SharedAdBannerView = adBanner; 
    } else {
        adBanner = SharedAdBannerView;
}

SharedAdBannerView 是 TN2286 中定义的一个宏,它使用应用委托(delegate)上定义的实例变量(这就是它在显示 iAd 的所有 View 之间保持共享的方式)。我还决定在将广告横幅从屏幕上移开之前将其从 View 层次结构中移除,因为一个场景正在切换到另一个场景。我阅读文档时说,只要广告横幅是 View 层次结构的一部分,您就会收到该消息——换句话说,隐藏横幅 View 并不是阻止警告消息的方法。或者换句话说,如果隐藏广告横幅就足够了,它对我不起作用,也无助于故障排除。当我遇到 TN2239 时,我学到了很多东西,它在 gdb 中提供了这个技巧:

 po [[self view] recursiveDescription];

您必须根据放置断点的位置调整向其发送 recursiveDescription 消息的对象,但可能 [self view] 没问题。

关于ios - 我隐藏了我的 AdBannerView 但仍然收到警告横幅 View (0x9c75550) 有广告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7960866/

相关文章:

ios - 获取主视图 Controller 中子容器 View 中 tableView 的引用

jquery - CSS 3 - 模糊效果叠加模态背景

ios - Swift iAd - 超过 10 个 ADBannerView 警告和 CGAffineTransformInvert 实例 : singular matrix output

ios - 如何以编程方式更改 UIDatePicker 的选定日期颜色 - Swift 4?

IOS 设备方向停留在纵向模式,没有横向

iOS:创建链接按钮

javascript - 为什么我的模态窗口在点击后没有关闭?

jquery - Bootstrap 模式关闭时 YouTube 视频仍在播放

ios - 将 canDisplayBannerAds 更改为 NO 不会更新 View 以删除广告横幅

iphone - 在bannerViewActionDidFinish : Bug or Not?之后AdBannerView移动到 super View 的顶部