Tuesday, September 10, 2013

Place a static GADBanner into a UIViewController

Place a static GADBanner into a UIViewController

I am looking to add AdMob banners throughout my app. I have placed them
into the bottom of every screen and it works correctly, but not entirely
when it comes to UIViewControllers.
When I put an add onto the UIViewController it is starting in the correct
spot on the bottom of the screen, but when I scroll the table it moves
with it. I need the ad to statically stay at the bottom of the screen as I
scroll the table.
Here is my code:
- (void)displayGAD
{
// The frame of the banner is initialized off screen.
// If an ad loads then it will animate onto the screen.
self.bannerView = [[GADBannerView alloc] initWithFrame:CGRectMake(0.0,
self.view.frame.size.height,
GAD_SIZE_320x50.width,
GAD_SIZE_320x50.height)];
self.bannerView.adUnitID = self.adUnitID;
self.bannerView.delegate = self;
self.bannerView.rootViewController = self;
[self.view addSubview:self.bannerView];
[self.bannerView loadRequest:[self createRequest]];
}
- (GADRequest *)createRequest
{
GADRequest *request = [GADRequest request];
#warning Comment this out before distribution
request.testDevices = [NSArray
arrayWithObjects:@"84ea3d9789cabb0a34176cbb52c0f992",
@"abf08fe141b95987d27ac068602605b8", GAD_SIMULATOR_ID, nil];
return request;
}
- (void)adViewDidReceiveAd:(GADBannerView *)view
{
NSLog(@"Received Ad");
[UIView animateWithDuration:1.0 animations:^ {
view.frame = CGRectMake(0.0,
self.view.frame.size.height -
view.frame.size.height,
view.frame.size.width,
view.frame.size.height);
}];
}
- (void)adView:(GADBannerView *)view
didFailToReceiveAdWithError:(GADRequestError *)error
{
NSLog(@"Failed to receive ad with error: %@", [error
localizedFailureReason]);
}
I have seen multiple example's as to how I can embed an ad into the table
view, but not anything concrete for how I want to do it. The only thing
that I have read in regards to this is that I should put the table view
into a container view and then add the ad into that as well. I don't know
how I would do that, though, since this is a UITableViewController.

No comments:

Post a Comment