David26th
David26th

Reputation: 401

How do I hide iAd banners when no ads are being served?

Anyone able to offer a little help on this? I just received feedback from Apple advising my app could not be accepted because it contained adbanners that were still visible when no ads were being served, trouble is I can't figure out quite what to do to prevent this problem.

[QUOTE]

We've completed the review of your application; however, we cannot post this version to the App Store because it displays an empty iAd banner when ad content is not available. The banner within the app should be hidden whenever ad content is not being served by iAd. We have included additional details below to help explain the issue. We hope that you'll consider revising and resubmitting your application.

To handle the case where ad content is not available, you will need to implement a banner view delegate. An example code snippet is included here for your convenience. Additionally, you may wish to review the section "Working with Banner Views" of the iAd Programming Guide for specific details: https://developer.apple.com/iphone/prerelease/library/documentation/UserExperience/Conceptual/iAd_Guide/WorkingwithBannerViews/WorkingwithBannerViews.html

Banner View Delegate to Remove a Banner View When Advertisements are Not Available:

 - (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
 {
  if (self.bannerIsVisible)
   {
       [UIView beginAnimations:@"animateAdBannerOff" context:NULL];
 // assumes the banner view is at the top of the screen.
       banner.frame = CGRectOffset(banner.frame, 0, -50);
       [UIView commitAnimations];
       self.bannerIsVisible = NO;
   }
 }

Now what I'm struggling withs is what to do with that code, when I've tried putting it in it just throws out several red errors so I come seeking advice, anyone able to help me out here?

EDIT: Main viewcontroller Code as requested by a poster

    //
//  MainViewController.m
//  GBSoundboard4
//
//  Created by David Clarke on 19/06/2010.
//  Copyright __MyCompanyName__ 2010. All rights reserved.
//

#import "MainViewController.h"
#import <AVFoundation/AVAudioPlayer.h>

@implementation MainViewController
-(IBAction)goodafternoon {
    NSString *path = [[NSBundle mainBundle] pathForResource:@"goodafternoon" ofType:@"wav"];
    AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
    [theAudio play];
}

-(IBAction)jollygood {
    NSString *path = [[NSBundle mainBundle] pathForResource:@"jollygood" ofType:@"wav"];
    AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
    [theAudio play];
}
-(IBAction)playSound {
    NSString *path = [[NSBundle mainBundle] pathForResource:@"goodmorning" ofType:@"wav"];
    AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];

    [theAudio play];
}

-(IBAction)upgrade {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://itunes.apple.com/gb/app/the-great-british-soundboard/id376263018?mt=8"]];
}



/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/


- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller {

    [self dismissModalViewControllerAnimated:YES];
}


- (IBAction)showInfo:(id)sender {    

    FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:@"FlipsideView" bundle:nil];
    controller.delegate = self;

    controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:controller animated:YES];

    [controller release];
}


- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc. that aren't in use.
}


- (void)viewDidUnload {
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations.
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/


- (void)dealloc {
    [super dealloc];
}


@end

Upvotes: 2

Views: 9040

Answers (3)

William Jockusch
William Jockusch

Reputation: 27285

There is a GREAT example of how to implement this in WWDC 2010 session video 112. If you are enrolled in the iPhone developer program, you can download it from iTunes University, as described below.

Assuming you are in the Apple Developer Program, you received an Email entitled "WWDC for everyone." Follow the links in that Email until you get to iTunes University. Then follow the link for frameworks, and pick session 112. I think the implementation is at approximately the 25 minute mark.

Upvotes: 1

Brad Larson
Brad Larson

Reputation: 170309

You need to do exactly what they describe. First, you need to make your MainViewController the delegate for your ADBannerView instance. Then, just copy and paste the code they've handed you into your MainViewController's implementation. This assumes that your banner appears at the bottom of the screen. If it appears at the top, reverse the direction of animation in the code they've provided.

If your banner fails to load an ad (which it will do until July 1 when the service goes live, and even after that if not attached to the network or if inventory drops), this delegate method will be called. Additionally, you can respond to other delegate callbacks that are described in the ADBannerViewDelegate protocol.

As they suggest, this is covered in the appropriate section of the iAd Programming Guide.

Upvotes: 0

Robert Redmond
Robert Redmond

Reputation: 1522

What you need to do is this event - (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)

Is make your view that is with the bannerView cover up the banner by resizing its frame to cover the bannerView space on your screen and move the origin of the bannerView frame outside the screen

B then on - (void)bannerViewDidLoadAd:(ADBannerView *)banner

resize your view to make room for the BannerView and move the origin of the bannerView frame back to the space on the screen.

Upvotes: 4

Related Questions