Phonegap screen and implementation problems

267 views
Skip to first unread message

Musa Sağlam

unread,
Jan 17, 2014, 3:56:58 AM1/17/14
to google-adm...@googlegroups.com

Hi there,


what i've done:

  • Added Code in MainViewController.m

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

iOS-Simulator_l.png
iOS-Simulator_p.png

Musa Sağlam

unread,
Jan 21, 2014, 2:12:32 PM1/21/14
to google-adm...@googlegroups.com
Has nobody any idea?
Is additional information needed?

Eric Leichtenschlag

unread,
Jan 21, 2014, 7:48:36 PM1/21/14
to google-adm...@googlegroups.com
Hi Musa,

Check out this blog post on how to work with the smart banner format. You'll have to listen for orientation change and set the ad size to kGADAdSizeSmartBannerLandscape when the app changes to landscape, and kGADAdSizeSmartBannerPortrait when the app changes back to portrait. This is because the ad size doesn't change once it's defined. From your second picture, it looks like you defined a kGADAdSizeSmartBannerLandscape size, which is 1024x90 on an iPad. When you change to portrait, it's showing you a 1024x90 ad which is too wide. If you change the ad size to kGADAdSizeSmartBannerPortrait, the view change be 768x90 and automatically load a new ad for you that'll fit the screen.

Cheers,
Eric

Musa Sağlam

unread,
Jan 25, 2014, 10:45:21 AM1/25/14
to google-adm...@googlegroups.com
Hi Eric,

thanks a lot for your post.

I've wrote the code like its explained but have still a problem.
My app is landscape-only because of the story-telling. So i've locked the portrait-mode in XCode:

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

MainViewController.m

#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

Eric Leichtenschlag

unread,
Jan 27, 2014, 4:41:58 PM1/27/14
to google-adm...@googlegroups.com
Hey Musa,

I'm not sure exactly how it showed up at that height, but that image you're showing looks like it is a kGADAdSizeSmartBannerPortrait banner (it's width looks like height of the device in landscape). Since your app is landscape only, you should be able to remove the entire willAnimateRotationToInterfaceOrientation: code because you never expect to have a banner in portrait.

If you're still getting issues with the ad showing up in the middle of the screen, it may be helpful to log what the origin is after your 

CGPoint origin = CGPointMake(0.0,
                                 self.view.frame.size.height -
                                 CGSizeFromGADAdSize(
                                                     kGADAdSizeSmartBannerLandscape).height);

code. Or digging further, figure out exactly what the values are for self.view.frame.size.height and CGSizeFromGADAdSize(kGADAdSizeSmartBannerLandscape).height and see if they are what you expect.

Thanks,
Eric

Musa Sağlam

unread,
Apr 21, 2014, 4:46:09 PM4/21/14
to google-adm...@googlegroups.com
Hi Eric, hi to all other programmers,

I'm hopeless. I've tried everything I can and get no positive result.
It would be great, when somebody else can complete the last steps of my project.

Can you tell me, how it will cost, to solve my problem?
I just want to finish my project.

I'm waiting for your offers.

Best wishes
Musa
Reply all
Reply to author
Forward
0 new messages