I am trying to place one adbanner (admob banner) at the bottom of my application. But for now, using my code, it sometimes appears at the bottom or in the middle, like this. Please check the following screenshots


check my code
#import "LocViewController.h"
@interface LocViewController ()
{
UIInterfaceOrientation orientation1;
}
@end
#define MY_BANNER_UNIT_ID @"a152a98e7f64210"
@implementation LocViewController
- (void)viewDidLoad {
[super viewDidLoad];
if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft||[UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight)
{
bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerLandscape];
bannerView_.frame = CGRectMake(0,678,bannerView_.frame.size.width,bannerView_.frame.size.height);
}
else if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait||[UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerPortrait];
bannerView_.frame = CGRectMake(0,934,bannerView_.frame.size.width,bannerView_.frame.size.height);
}
bannerView_.adUnitID = MY_BANNER_UNIT_ID;
bannerView_.rootViewController = self;
[self.view addSubview:bannerView_];
[bannerView_ loadRequest:[GADRequest request]];
}
-(void)showAd:(NSString *)orient{
if([orient isEqualToString:@"l"]){
bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerLandscape];
bannerView_.frame = CGRectMake(0,678,bannerView_.frame.size.width,bannerView_.frame.size.height);
}else{
bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerPortrait];
bannerView_.frame = CGRectMake(0,934,bannerView_.frame.size.width,bannerView_.frame.size.height);
}
bannerView_.adUnitID = MY_BANNER_UNIT_ID;
bannerView_.rootViewController = self;
[self.view addSubview:bannerView_];
[bannerView_ loadRequest:[GADRequest request]];
}
-(void)viewWillAppear:(BOOL)animated{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
}
- (void)orientationChanged:(NSNotification *)notification{
[self adjustViewsForOrientation:[[UIApplication sharedApplication] statusBarOrientation]];
}
- (void) adjustViewsForOrientation:(UIInterfaceOrientation) orientation {
[bannerView_ removeFromSuperview];
if(orientation == UIInterfaceOrientationPortrait||orientation == UIInterfaceOrientationPortraitUpsideDown)
{
[self showAd:@"p"];
}
else if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft||[UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight)
{
[self showAd:@"l"];
}
}
-(void)viewDidDisappear:(BOOL)animated{
[[NSNotificationCenter defaultCenter]removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
source
share