sebastien
sebastien

Reputation: 2519

I hide my AdBannerView but still get WARNING A banner view (0x9c75550) has an ad

I have just added an ADBannerview in my App. I create the AdBannerView in my UIApplicationDelegate in order to have only one instance of it and I share it in the different viewController

Everything works perfectly except I get the warning message: ADBannerView: WARNING A banner view (0x9c75550) has an ad but may be obscured. This message is only printed once per banner view.

when I open a modal view (using presentModalViewController) on top of the view that is currently displaying the ADBannerview. Before opening the modal view I'm using the following code to hide the 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;
}

I don't understand what to do to not have this warning message. It seems the ADBannerView is successfully hidden (offscreen) before the Modal view is displayed.

I probably missed something but I cannot see it. Thanks for your help,

Sébastien.

Upvotes: 1

Views: 1547

Answers (1)

tobinjim
tobinjim

Reputation: 1852

Sébastien, I hope you've moved on from this since the question has gone unanswered for so many months. I recently added iAd support and found this warning to be quite annoying too. One of the subtleties of sharing an ad banner is that if you want to show it in your initial view controller, you have to do most of the setup in that view controller, not in the app delegate.

This is the viewWillAppear: method in my initial view controller:

- (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 is a macro as defined in the TN2286, and it is utilizing an instance variable defined on the app delegate (which is how it remains shared amongst all views that display an iAd). I also decided to animate the ad banner off the screen before removing it from the view hierarchy as one scene was segueing to another scene. I read the documentation as saying that whenever an ad banner is a part of a view hierarchy you would get that message -- in other words, hiding the banner view isn't the way to prevent the warning message. Or put differently, if it is sufficient to hide the ad banner, it didn't work for me and it didn't help in troubleshooting. I learned a lot when I came across TN2239 which offered this tip in gdb:

 po [[self view] recursiveDescription];

You have to adjust the object to whom you send the recursiveDescription message based on where you placed your breakpoint, but probably [self view] is fine.

Upvotes: 1

Related Questions