0

We're building an iPhone app and using this iAd plugin: https://github.com/shazron/iAdPlugin/blob/master/SAiOSAdPlugin.m.

Since we're on PhoneGap, we built the app with HTML5, not Objective-C, and don't know how to adjust the plug-in.

Right now, when iAd lacks inventory, it displays a white rectangle (320x50). When this happens, we would like to display a 320x50 web page instead of the white rectangle, acting as a fallback ad. When iAd has an inventory to show again, we would like to hide this web page and show iAd again.

Can someone provide some tips on how to do this?

Thanks!

Crashalot
  • 33,605
  • 61
  • 269
  • 439
  • How about displaying it when you recv `- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError*)error`? – Groot May 28 '13 at 07:53
  • Right, but how do we add the view and display it (while hiding the other view)? Thanks for your help, and sorry if this is a stupid question! – Crashalot May 28 '13 at 07:56

1 Answers1

0

Take a look at this code I've written doing essentially the same thing. Really note that this is simple a copy paste from one of my projects but I think the concept gets across. Ask if something is unclear! The basics is that I have a iAd-banner called bannerView and an own banner called noIADImageView. If the iAd fails to load I hide it in favor of the the noIADImageView

Banner setup (Called from e.g. viewDidLoad):

- (void) setupTheAdBanners {
    // Adding the killer whales ad-banner if the iAds fail to provide an ad.
    [self setupKillerWhalesBanner];

    [bannerView setHidden:YES];
    [noIADImageView setHidden:NO];

    [bannerView setDelegate:self];

    // and make sure it's positioned onscreen.
    bannerView.frame = CGRectMake(0.0, 0.0, bannerView.frame.size.width, bannerView.frame.size.height);
    noIADImageView.frame = bannerView.frame;

    // bring your bannerView to the front
    [self.view bringSubviewToFront:bannerView];
    [self.view bringSubviewToFront:noIADImageView];
}

- (void) setupKillerWhalesBanner {
    //Adding the banner as a subview
    [self.view addSubview:bannerView];

    // Initializing the UIImageView that will show only if the iAd do not display any ads

    CGRect frameBan = CGRectMake(bannerView.frame.origin.x,bannerView.frame.origin.y-bannerView.frame.size.height,bannerView.frame.size.width,bannerView.frame.size.height);

    noIADImageView = [[UIImageView alloc] initWithFrame:frameBan];
    NSLog(@"%f,%f,%f,%f",bannerView.frame.origin.x,bannerView.frame.origin.y-bannerView.frame.size.height,bannerView.frame.size.width,bannerView.frame.size.height);

    [noIADImageView setImage:[UIImage imageNamed:(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? @"KillerWhalesBanner-iPad.png" : @"KillerWhalesBanner-iPhone.png")]];

    // ...as hidden
    [noIADImageView setHidden:NO];

    // Setting up a Tap regognizor for the UIImageView
    UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc]
                                             initWithTarget:self action:@selector(clickEventOnImage:)];
    [tapRecognizer setNumberOfTouchesRequired:1];
    [tapRecognizer setDelegate:self];

    // Enables user interaction to the UIImageView
    noIADImageView.userInteractionEnabled = YES;
    [noIADImageView addGestureRecognizer:tapRecognizer];
}

-(void)clickEventOnImage:(id) sender { // Open the Killer Whales app.
    NSLog(@"Clicked banner");
    [self playClickSound];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://itunes.apple.com/us/app/killer-whales/id503511808?mt=8"]];
}

When the banner fails to load i hide it in favor of the noIADImageView as

-(void) bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
    // Failed to load a banner
    NSLog(@"Error with message: %@",error);

    if(error) { //Some sort of error
        [banner setHidden:YES];
        [noIADImageView setHidden:NO];
    }

}
Groot
  • 13,943
  • 6
  • 61
  • 72
  • to clarify, we add clickEventOnImage, setupKillerWhalesBanner, and setupTheAdBanners to SAiOSAdPlugin.m while replacing didFailToReceiveAdWithError with your version? thanks so much for the help! – Crashalot May 28 '13 at 08:45
  • Since I'm not familiar with the SAiOSAdPlugin it is difficult to tell. I'm merely trying to convey an idea of how to achieve what you are after that has in fact worked for me before. – Groot May 28 '13 at 08:56
  • we tried using your code, but the UIWebView won't appear. we posted the question here if you could help: http://stackoverflow.com/questions/16867493/trouble-hiding-iad-banner-and-displaying-uiwebview-in-its-place. thanks again. – Crashalot Jun 01 '13 at 03:26