Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Admob banner not aligning correctly in landscape on iOS — Gideros Forum

Admob banner not aligning correctly in landscape on iOS

NatWobbleNatWobble Member
edited July 2016 in Plugins
Hi. We are trying to display Admob banners center/bottom in landscape on iOS. They display correctly on an iPhone 4 running iOS 7 but on my iPad running iOS 9 they are displaying as if the dimensions taken are in portrait (We experimented with setting them left/center and they are displaying 2/3 of the way down the screen and center/top they are shifted to the left a bit). They're fine on Android. The Gideros project is set to letterbox landscape left and xcode is set to landscape left and landscape right.

I've tried both the 7.5.2 and 7.8.1 versions of the GoogleMobileAds framework, which work fine in our other app in portrait. Xcode never seems to like the one bundled with Gideros for some reason.

Have you got any ideas how we can solve this? Many thanks in advance.

Comments

  • simwhisimwhi Member
    Does anyone know how to fix this?
  • Still no luck. In AdsClass.mm I tried setting:

    +(BOOL)isPortrait{
    return NO;
    }

    and gdr_initialize(..., false) in AppDelegate.m as in these instructions in an old thread.

    I even swapped around some of the height and width values in setAlignment in AdsClass.mm, which fixed it for the iPad (iOS 9.3.2) but broke it for the old iPhone 4 running iOS 7.

    Please can you help @ar2rsawseen ? There's definitely something strange going on with how the orientations are being reported on different iOS devices.







  • Ok I fiddled with the AdsClass.mm file with some ideas from this thread and got it working for the setAlignment function:
    +(void)setAlignment:(NSString*)adprovider with:(NSString*)hor andWith:(NSString*)ver{
    	id ad = [ads objectForKey:[adprovider lowercaseString]];
        if (ad) {
    		UIView *view_ = [ad getView];
    		if(view_ != nil)
    		{
    			float x = 0;
    			float y = 0;
    			float screenWidth = 0;
    			float screenHeight = 0;
     
    			CGRect screenRect = [[UIScreen mainScreen] bounds];
    			if (UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation]))
    			{
    				screenWidth = screenRect.size.width;
    				screenHeight = screenRect.size.height;
    			}
    			else
    			{
                    // --------- Amendment ---------
    				//screenWidth = screenRect.size.height;
    				//screenHeight = screenRect.size.width;
     
                   if([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0){
                     screenWidth = screenRect.size.width;
                     screenHeight = screenRect.size.height;
                   }
                   else{
                     screenWidth = screenRect.size.height;
                     screenHeight = screenRect.size.width;
     
                   }
                   //  ------------------------------
    			}
    			if([hor isEqualToString:<a href="https://forum.giderosmobile.com/profile/right" rel="nofollow">@right</a>]){
    				x = screenWidth - view_.frame.size.width;
    			}
    			else if([hor isEqualToString:<a href="https://forum.giderosmobile.com/profile/center" rel="nofollow">@center</a>]){
    				x = (screenWidth - view_.frame.size.width)/2;
    			}
     
    			if([ver isEqualToString:<a href="https://forum.giderosmobile.com/profile/bottom" rel="nofollow">@bottom</a>]){
                    y = screenHeight - view_.frame.size.height;
    			}
    			else if([ver isEqualToString:<a href="https://forum.giderosmobile.com/profile/center" rel="nofollow">@center</a>]){
    				y = (screenHeight - view_.frame.size.height)/2;
    			}
    			[view_ setFrame:CGRectMake(x, y, view_.frame.size.width, view_.frame.size.height)];
    		}
        }
    }
    I'm hoping it works ok on iOS 8 devices but I have none to test on. I assume everyone with an iPhone 4S and higher will be on iOS 9 by now and 8 behaves like iOS 9. It might be worth adding something like this to the ads plugin in the future but bearing in mind I hacked this together with no knowledge on object C. Everything seems to be working ok for now at least, but I'll need to do some more testing.

    Likes: antix, simwhi

    +1 -1 (+2 / -0 )Share on Facebook
  • ar2rsawseenar2rsawseen Maintainer
    @NatWobble that is ok, I hacked AdsInterface on no knowledge on objective C
    That is how coding works :)

    Will try to add it to Ads interface

    Likes: NatWobble

    +1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.