Implementing AdMob SDK(w/CocoaPods) iOS (cocos2d-x)

565 views
Skip to first unread message

Ismael Machado

unread,
Dec 12, 2018, 10:40:33 PM12/12/18
to google-adm...@googlegroups.com
Hello I am using cocos2d-x to build my game and for specific reasons I do not want to use the C++ SDK for admob, I want to implement it specifically with CocoaPods iOS.  I followed the tutorial here -> (https://developers.google.com/admob/ios/x-ad-rendering) and on my iPhone 6, 8 and XS the banner ad is showing , but if I test on iphone 5 (ios 9.0) or iphone 5/5s simulator(ios 8.1) it will tell me that 

<Google> Invalid Request. Invalid ad width or height: (320, 0)

2018-12-12 21:03:48.819 Ball[9781:886199] adView:didFailToReceiveAdWithError: Request Error: Invalid ad request parameter(s). Check the Xcode console for details.

and when I hard code a value then the error will change to 'request error: no ad to show' even if i run it on my physical iPad that is (iOS 8.1) it will say "invalid ad width or height: (760, 0)" 

So i created a regulor iOS project and copied the exact same code and then the ad showed on my iphone 5(9.1) and iPhone 5s simulator(iOS8.1) with no problem. this is easily reproducible its weird that in my cocos2d-x project the banner shows fine on iphoneXS simulator and iphone 6 simulator but not on iphone 5s(iOS 8.1) . but on a regular iOS project the banner shows fine on all the devices and simulators by the way I am using Xcode 10.1 

if you create a brand new cocos2d-x project and just add this code you will be able to see what I am talking about

in AppController.h I do #import "GoogleMobileAds/GoogleMobileAds.h"

in AppController.mm I add [GADMobileAds configureWithApplicationID:@"ca-app-pub-3940256099942544~1458002511"]; to application didFinishLaunchingWithOptions


and in RootViewController.h I add @property(nonatomic, strong) GADBannerView *bannerView; to the interface

then in RootViewController.m I add the template code to viewDidLoad and add the methods 


**I could send you both the Cocos2d-X and the regular iOS project that both have this exact same code implemented below and you can run it on iOS9 & iOS8(iphone5s and probably other ios8&ios9 simulators) so you can see what im talking about**


  self.bannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
 
[self addBannerViewToView:self.bannerView];

 
// Replace this ad unit ID with your own ad unit ID.
 
self.bannerView.adUnitID = @"ca-app-pub-3940256099942544/2934735716";
 
self.bannerView.rootViewController = self;
 
GADRequest *request = [GADRequest request];
 
[self.bannerView loadRequest:request];

#pragma mark - view positioning

-(void)addBannerViewToView:(UIView *_Nonnull)bannerView {
 
self.bannerView.translatesAutoresizingMaskIntoConstraints = NO;
 
[self.view addSubview:self.bannerView];
 
if (@available(ios 11.0, *)) {
   
[self positionBannerViewAtBottomOfSafeArea:bannerView];
 
} else {
   
[self positionBannerViewAtBottomOfView:bannerView];
 
}
}

- (void)positionBannerViewAtBottomOfSafeArea:(UIView *_Nonnull)bannerView NS_AVAILABLE_IOS(11.0) {
 
// Position the banner. Stick it to the bottom of the Safe Area.
 
// Centered horizontally.
 
UILayoutGuide *guide = self.view.safeAreaLayoutGuide;
 
[NSLayoutConstraint activateConstraints:@[
   
[bannerView.centerXAnchor constraintEqualToAnchor:guide.centerXAnchor],
   
[bannerView.bottomAnchor constraintEqualToAnchor:guide.bottomAnchor]
 
]];
}

- (void)positionBannerViewAtBottomOfView:(UIView *_Nonnull)bannerView {
 
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:bannerView
                                                        attribute
:NSLayoutAttributeCenterX
                                                        relatedBy
:NSLayoutRelationEqual
                                                           toItem
:self.view
                                                        attribute
:NSLayoutAttributeCenterX
                                                       multiplier
:1
                                                         constant
:0]];
 
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:bannerView
                                                        attribute
:NSLayoutAttributeBottom
                                                        relatedBy
:NSLayoutRelationEqual
                                                           toItem
:self.bottomLayoutGuide
                                                        attribute
:NSLayoutAttributeTop
                                                       multiplier
:1
                                                         constant
:0]];
}

@end

mobileadssdk-a...@google.com

unread,
Dec 13, 2018, 6:12:19 AM12/13/18
to Ismael Machado, Google Mobile Ads SDK Developers
Hi,

Thank you for reaching out to us and providing the details of your concern.

We will look into this and get back to you for any feedback.

Regards,
Teejay Pimentel
Mobile Ads SDK Team

On 12/13/18 11:40:33 izzy.ma...@gmail.com wrote:
Hello I am using cocos2d-x to build my game and for specific reasons I do not want to use the C++ SDK for admob, I want to implement it specifically with CocoaPods iOS.  I followed the tutorial here -> (https://developers.google.com/admob/ios/x-ad-rendering) and on my iPhone 6, 8 and XS the banner ad is showing , but if I test on iphone 5 (ios 9.0) or iphone 5/5s simulator(ios 8.1) it will tell me that 

<Google> Invalid Request. Invalid ad width or height: (320, 0)

2018-12-12 21:03:48.819 Ball[9781:886199] adView:didFailToReceiveAdWithError: Request Error: Invalid ad request parameter(s). Check the Xcode console for details.

and when I hard code a value then the error will change to 'request error: no ad to show' 

So i created a regulor iOS project and copied the exact same code and then the ad showed on my iphone 5(9.1) and iPhone 5s simulator(iOS8.1) with no problem. this is easily reproducible its weird that in my cocos2d-x project the banner shows fine on iphoneXS simulator and iphone 6 simulator but not on iphone 5s(iOS 8.1) . but on a regular iOS project the banner shows fine on all the devices and simulators by the way I am using Xcode 10.1 

if you create a brand new cocos2d-x project and just add this code you will be able to see what I am talking about

in AppController.h I do #import "GoogleMobileAds/GoogleMobileAds.h"

in AppController.mm I add [GADMobileAds configureWithApplicationID:@"ca-app-pub-3940256099942544~1458002511"]; to application didFinishLaunchingWithOptions


and in RootViewController.h I add @property(nonatomic, strong) GADBannerView *bannerView; to the interface

then in RootViewController.m I add the template code to viewDidLoad and add the methods 


--

---
You received this message because you are subscribed to the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads-sdk+unsubscrib...@googlegroups.com.
To post to this group, send email to google-admob-ads-sdk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-admob-ads-sdk/e6e53ee9-c417-4551-95a9-9cf580bdb57e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ismael Machado

unread,
Dec 13, 2018, 8:16:53 AM12/13/18
to Google Mobile Ads SDK Developers
Ok thanks very much , I know ios8&9 don’t have a lot of market share but it would still be nice to have the ads working on them.

Ismael Machado

unread,
Dec 13, 2018, 8:11:30 PM12/13/18
to google-adm...@googlegroups.com
.UPDATE: i followed this tutorial and now it is working weird.

ANOTHER UPDATE: after following the tutorial and trying to implement the constraints I pin pointed the issue so if you create a new cocos2d-x project and add the code I mentioned in side of this method it will not load on iOS 8 & 9
- (void)positionBannerViewFullWidthAtBottomOfView:(UIView *_Nonnull)bannerView {
 
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:bannerView
                                                        attribute
:NSLayoutAttributeLeading
                                                        relatedBy
:NSLayoutRelationEqual
                                                           toItem
:self.view
                                                        attribute
:NSLayoutAttributeLeading

                                                       multiplier
:1
                                                         constant
:0]];
 
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:
bannerView
                                                        attribute
:NSLayoutAttributeTrailing
                                                        relatedBy
:NSLayoutRelationEqual
                                                           toItem
:self.view
                                                        attribute
:NSLayoutAttributeTrailing

                                                       multiplier
:1
                                                         constant
:0]];
 
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:bannerView
                                                        attribute
:NSLayoutAttributeBottom
                                                        relatedBy
:NSLayoutRelationEqual
                                                           toItem
:self.bottomLayoutGuide
                                                        attribute
:NSLayoutAttributeTop
                                                       multiplier
:1
                                                         constant
:0]];
}

sidenote: i still need help on this topic https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/google-admob-ads-sdk/9kieotl7zmM/OTc6MzW8CgAJ

mobileadssdk-a...@google.com

unread,
Dec 17, 2018, 3:18:29 PM12/17/18
to Ismael Machado, Google Mobile Ads SDK Developers
Hey Ismael,

Glad you were able to resolve your issue.

- Ram


=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+ page:
    http://googleadsdeveloper.blogspot.com
    https://plus.google.com/115658573333388777174/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

On 12/13/18 17:11:30 izzy.ma...@gmail.com wrote:
UPDATE: i followed this tutorial and now it is working weird 

--

---
You received this message because you are subscribed to the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.

To post to this group, send email to google-admob-ads-sdk@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages