I do not manage to have iAd working in storyboard, within a UITableViewController.
This is basically what I have done so far: In storyboard, I have dragged an iAd banner view in the bottom of the scene of my UITableViewController. (I was not able to set the banner in the view itself as storyboard prevents it. I could only drag the iAd object next to the first responder and UITableViewController's icons.)
In the header of the UITAbleViewController, I have:
#import <UIKit/UIKit.h>
#import "ListViewController.h"
#import <iAd/iAd.h>
@interface ListViewController : UITableViewController <ADBannerViewDelegate>{
bool bannerIsVisible;
}
@property (strong, nonatomic) IBOutlet ADBannerView *iAd;
@end
In the implementation of the UITableViewController, I have:
- (void)viewDidLoad
{
[super viewDidLoad];
iAd.delegate = self;
// iAd.frame = CGRectMake(0.0,200.0,iAd.frame.size.width,iAd.frame.size.height); // does not work
// self.tableView.tableFooterView = iAd; // Display the banner at the middle of the screen (depending upon the number item of the table)
// Do not know how to have the default banner to appear at the very bottom of the screen (behind the tab bar) when the view is loaded ?
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
NSLog(@"didFailToReceiveAdWithError");
if (bannerIsVisible)
{
[UIView beginAnimations:@"animateAdBannerOff" context:NULL];
banner.frame = CGRectMake(0.0,350.0,banner.frame.size.width,banner.frame.size.height);
[UIView commitAnimations];
bannerIsVisible = NO;
}
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
NSLog(@"bannerViewDidLoadAd");
if (!bannerIsVisible)
{
[UIView beginAnimations:@"animateAdBannerOn" context:NULL];
banner.frame = CGRectMake(0.0,317.0,banner.frame.size.width,banner.frame.size.height);
[UIView commitAnimations];
bannerIsVisible = YES;
}
}
The idea is to have the banner appearing at the bottom of the screen and to show it above the tab bar is the banner load is succesfulf.
The problem I have: with this configuration I can see that sometimes the method "didFailToReceiveAdWithError" is called and sometimes the "bannerViewDidLoadAd" one, but in each case the banner is not shown.