Hi there,
The result is very different, if i test it direct on my device (iPad 2)
on the iOS-Simulator (ipad)
My problem:
How can i get the right AdSize-Format for my application (landscape only). I've tested especially the FullSizeBanner (468 x 60). But you can see, that there isnt the same behavior on the device and on the ios-simulator.
Did i forget something?
Best wishes
Musa
But when i launch the application, the ad is shown in the middle of the screen:
Can you understand why it behaves like this?
Here's my code:
MainViewController.h
#import <Cordova/CDVViewController.h>
#import <Cordova/CDVCommandDelegateImpl.h>
#import <Cordova/CDVCommandQueue.h>
// --------------------------------------------------------------------
#import "GADBannerView.h"
@interface MainViewController : CDVViewController {
// Declare one as an instance variable
GADBannerView *bannerView_;
}
@end
// --------------------------------------------------------------------
@interface MainCommandDelegate : CDVCommandDelegateImpl
@end
@interface MainCommandQueue : CDVCommandQueue
@end
#import "MainViewController.h"
// --------------------------------------------------------------------
#define MY_BANNER_UNIT_ID @"ca-app-pub-1625714993061995/3494107064"
// --------------------------------------------------------------------
@implementation MainViewController
- (id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Uncomment to override the CDVCommandDelegateImpl used
// _commandDelegate = [[MainCommandDelegate alloc] initWithViewController:self];
// Uncomment to override the CDVCommandQueue used
// _commandQueue = [[MainCommandQueue alloc] initWithViewController:self];
}
return self;
}
- (id)init
{
self = [super init];
if (self) {
// Uncomment to override the CDVCommandDelegateImpl used
// _commandDelegate = [[MainCommandDelegate alloc] initWithViewController:self];
// Uncomment to override the CDVCommandQueue used
// _commandQueue = [[MainCommandQueue alloc] initWithViewController:self];
}
return self;
}
- (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.
}
#pragma mark View lifecycle
- (void)viewWillAppear:(BOOL)animated
{
// View defaults to full size. If you want to customize the view's size, or its subviews (e.g. webView),
// you can do so here.
[super viewWillAppear:animated];
}
// --------------------------------------------------------------------
- (void)viewDidLoad {
[super viewDidLoad];
// Create a view of the standard size at the bottom of the screen.
// Initialize the banner docked to the bottom of the screen.
// We start in a portrait orientation so use kGADAdSizeSmartBannerPortrait.
CGPoint origin = CGPointMake(0.0,
self.view.frame.size.height -
CGSizeFromGADAdSize(
kGADAdSizeSmartBannerLandscape).height);
bannerView_ = [[[GADBannerView alloc]
initWithAdSize:kGADAdSizeSmartBannerLandscape
origin:origin] autorelease];
//Continue rest of initialization here
// ********************************************************************
// bannerView_ = [[GADBannerView alloc]
// initWithFrame:CGRectMake(0.0,
// self.view.frame.size.height -
// GAD_SIZE_320x50.height,
// GAD_SIZE_320x50.width,
// GAD_SIZE_320x50.height)];
// ********************************************************************
// Specify the ad's "unit identifier." This is your AdMob Publisher ID.
bannerView_.adUnitID = MY_BANNER_UNIT_ID;
// Let the runtime know which UIViewController to restore after taking
// the user wherever the ad goes and add it to the view hierarchy.
bannerView_.rootViewController = self;
[self.view addSubview:bannerView_];
// Initiate a generic request to load it with an ad.
[bannerView_ loadRequest:[GADRequest request]];
}
- (void)viewDidUnload {
[bannerView_ release];
}
- (void)dealloc {
[super dealloc];
}
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInt
duration:(NSTimeInterval)duration {
// The updated y value for the origin.
CGFloat yLocation;
// Set a new frame to update the origin on orientation change. Remember to set
// adSize first before you update the frame.
if (UIInterfaceOrientationIsLandscape(toInt)) {
bannerView_.adSize = kGADAdSizeSmartBannerLandscape;
yLocation = self.view.frame.size.width -
CGSizeFromGADAdSize(kGADAdSizeSmartBannerLandscape).height;
} else {
bannerView_.adSize = kGADAdSizeSmartBannerPortrait;
yLocation = self.view.frame.size.height -
CGSizeFromGADAdSize(kGADAdSizeSmartBannerPortrait).height;
}
CGRect frame = bannerView_.frame;
frame.origin = CGPointMake(0.0, yLocation);
bannerView_.frame = frame;
}
@end
// --------------------------------------------------------------------
// ********************************************************************
//- (void)viewDidUnload
//{
// [super viewDidUnload];
// // Release any retained subviews of the main view.
// // e.g. self.myOutlet = nil;
//}
//
//- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
//{
// // Return YES for supported orientations
// return [super shouldAutorotateToInterfaceOrientation:interfaceOrientation];
//}
//
///* Comment out the block below to over-ride */
//
///*
//- (UIWebView*) newCordovaViewWithFrame:(CGRect)bounds
//{
// return[super newCordovaViewWithFrame:bounds];
//}
//*/
//
//#pragma mark UIWebDelegate implementation
//
//- (void)webViewDidFinishLoad:(UIWebView*)theWebView
//{
// // Black base color for background matches the native apps
// theWebView.backgroundColor = [UIColor blackColor];
//
// return [super webViewDidFinishLoad:theWebView];
//}
/* Comment out the block below to over-ride */
/*
- (void) webViewDidStartLoad:(UIWebView*)theWebView
{
return [super webViewDidStartLoad:theWebView];
}
- (void) webView:(UIWebView*)theWebView didFailLoadWithError:(NSError*)error
{
return [super webView:theWebView didFailLoadWithError:error];
}
- (BOOL) webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
return [super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType];
}
*/
//@end
// ********************************************************************
@implementation MainCommandDelegate
/* To override the methods, uncomment the line in the init function(s)
in MainViewController.m
*/
#pragma mark CDVCommandDelegate implementation
- (id)getCommandInstance:(NSString*)className
{
return [super getCommandInstance:className];
}
/*
NOTE: this will only inspect execute calls coming explicitly from native plugins,
not the commandQueue (from JavaScript). To see execute calls from JavaScript, see
MainCommandQueue below
*/
- (BOOL)execute:(CDVInvokedUrlCommand*)command
{
return [super execute:command];
}
- (NSString*)pathForResource:(NSString*)resourcepath;
{
return [super pathForResource:resourcepath];
}
@end
@implementation MainCommandQueue
/* To override, uncomment the line in the init function(s)
in MainViewController.m
*/
- (BOOL)execute:(CDVInvokedUrlCommand*)command
{
return [super execute:command];
}
@end
CGPoint origin = CGPointMake(0.0, self.view.frame.size.height - CGSizeFromGADAdSize( kGADAdSizeSmartBannerLandscape).height);