is there a way to load admob ads in the background

3,447 views
Skip to first unread message

Gino

unread,
Jan 8, 2013, 12:42:54 PM1/8/13
to google-adm...@googlegroups.com
I noticed that when I load ads in my iOS game, they seem to cause noticeable pauses in the game, probably due to the ads being loaded in the UI thread.


So, to attenuate the glitches, I tried loading the ads using performSelectorInBackground (see below). Unfortunately, it looks like the loadRequest call needs to be running on the UI thread, as I get the following error:

    "Tried to obtain the web lock from a thread other than the main thread or the web thread"

Is there a way to load admob ads in such a way that they don't tie up the UI thread ?


    [self performSelectorInBackground:@selector(loadAdInBackground:) withObject:nil];


- (void)loadAdInBackground:(id) sender

{

    CCLOG(@" making call to loadRequest ..");

    [_adBannerView loadRequest:_adRequest];

    CCLOG(@" finished making call to loadRequest ..");

}



JDTheProgrammer

unread,
Jan 8, 2013, 11:18:34 PM1/8/13
to google-adm...@googlegroups.com
I think it would be against the policies of Admob to load the ads in the background.
From what I understand, if you load an ad in bg, admob server will count it as an actual ad view.
If you do this repeatedly, it may lead you into getting your account terminated.

Before doing any such thing, ensure you have the advice of experts.


Gino

unread,
Jan 9, 2013, 12:15:52 PM1/9/13
to google-adm...@googlegroups.com
Perhaps I was asking the wrong question. Let me rephrase it:

Basically, I am developing a 60 fps game where I want the call to:   [_adBannerView loadRequest:_adRequest] to always return in less than 5 milliseconds. ( 1 sec/60 fps => 16.7 milliseconds, of which it 
would preferable that the loadRequest take no more than 30% of the 16.7 milliseconds available in each frame).

Is this feasible ?  If it currently is not feasible, can it be made feasible, perhaps by adding a couple more methods to handle the time delays in a fairly transparent fashion ?  Possibly, by adding a method
called:  isAdReadyNow .  If it returned NO, that would be an indication to wait another 5 seconds before querying it. And if isAdReadyNow returned YES, then the call to loadRequest was pretty much guaranteed to return in under 5 milliseconds.

I think the upside to all this would be that it would help provide a smoother game experience for end users..

And, if AdMob could provide this kind of latency guarantee, then I think it would be an additional reason to choose AdMob over its competitors..

Rajkumar Parameswaran

unread,
Jan 9, 2013, 1:19:14 PM1/9/13
to google-adm...@googlegroups.com
Unfortunately you're not going to be able to use loadRequest: on a background thread as we interact with the UIWebView in that method and of couse you can't do any UI interactions on background threads in iOS.

That said, loadRequest: does make an asynchronous request so it shouldn't be blocking your main thread in any way. Like you said then the pauses in your game is probably from the ads put into the view hierarchy.

Have you tried out changing the size of your OpenGL view and using a container UIView that you then put the ad into? Generally your frame rate is going to decrease if you place the GADBannerView on top of an OpenGL view because of the way drawing works there.

In terms of your recommendation for isAdReadyNow, like I said I'd try to confirm first whether it is the actual network request or whether it's adding the GADBannerView onto your OpenGL view that's creating your delay.

Gino

unread,
Jan 10, 2013, 2:30:18 PM1/10/13
to google-adm...@googlegroups.com
Hi Raj, 

   Re: "Have you tried changing the size of your OpenGL view and using a container UIView that you then put the ad into?" 

Your suggestion worked really well for me.  I also found this related post by you that gives more detailed instructions on the matter (http://googleadsdeveloper.blogspot.com/2012/07/getting-admob-ads-to-work-with-cocos2d.html ). 

One caveat, the first ad load always seems to cause a bit of a pause in the game, but this should be a very minor issue since it occurs only once and I can make it barely noticeable by loading the initial ad a few
seconds after my game app has been invoked..

With the change you recommended, my game runs smoothly during the ad loads/refreshes..

Thank you !

Gino.

Rajkumar Parameswaran

unread,
Jan 10, 2013, 8:21:00 PM1/10/13
to google-adm...@googlegroups.com
Glad to hear that helped you out


--
 
 
 

iab...@live.com

unread,
Jun 24, 2013, 10:06:26 AM6/24/13
to google-adm...@googlegroups.com
Hi,
I've been experiencing the same problem with the drop of frame rate, after implementing AdMob mediation. I have tried putting the GADBannerView in a separate UIView, but that didn't changed anything. Can you please explain in more details how to resize the OpenGLView because when i try to resize the CCDirector view, the whole game is scaled. I am following your post (http://googleadsdeveloper.blogspot.com/2012/09/working-with-admob-and-cocos2d-v20.html) for Cocos2D integration.

Rajkumar Parameswaran

unread,
Jun 28, 2013, 7:30:12 PM6/28/13
to google-adm...@googlegroups.com
Unfortunately that's a side effect of scaling that CCDirector view (the whole game will be scaled). How much of a significant frame rate drop are you seeing when this doesn't happen?


--
 
---
You received this message because you are subscribed to the Google Groups "Google AdMob Ads Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

iab...@live.com

unread,
Jul 1, 2013, 7:25:40 AM7/1/13
to google-adm...@googlegroups.com
We were using AdMob mediation for our app and in the moments when there were ad animations or new ads, the frame rate was dropping down to 7 FPS and CPU usage was going up to 70% which lead to problems with the app animations. As we couldn't find any other solutions we went to only ads from AdMob and it solved the issue.
To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.

Rajkumar Parameswaran

unread,
Jul 3, 2013, 12:07:40 PM7/3/13
to google-adm...@googlegroups.com
Ahh I see. Unfortunately right now there's no way to disable those animations. One thing you may want to do is make sure that your ads are only being put into menu screens where dips in frame rate won't really negatively affect game performance.


To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads...@googlegroups.com.

Roy Hamm

unread,
Oct 14, 2013, 3:02:16 AM10/14/13
to google-adm...@googlegroups.com
Hi Gino. How did you do this?

I tried to adjust the size of the glView, but it does not seem to have any affect. Here is my code (relevant parts)

    window_ = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    

    CGRect adviewSize = [[UIScreen mainScreen] bounds];

    adviewSize.size.height = 50;

    adview = [[UIView alloc] initWithFrame:adviewSize];

    [window_ addSubview:adview];

 

    CGRect gameViewSize = [[UIScreen mainScreen] bounds];

    gameViewSize.size.height = gameViewSize.size.height - 50.0f;

    gameViewSize.origin.y = 50;


    CCGLView *glView = [CCGLView viewWithFrame:gameViewSize

  pixelFormat:kEAGLColorFormatRGB565

  depthFormat:0

        preserveBackbuffer:NO

        sharegroup:nil

 multiSampling:NO

       numberOfSamples:0];


Reply all
Reply to author
Forward
0 new messages