Calling GADBannerView's loadRequest: method on a background thread

481 views
Skip to first unread message

Pol Mum

unread,
Apr 7, 2014, 4:04:06 PM4/7/14
to google-adm...@googlegroups.com
Would it be possible to modify the iOS AdMob sdk to be able to call GADBannerView's loadRequest: method on a background thread?
I am aware that currently doing this fails because loadRequest uses the UIWebKit class, which has to be used from the main thread. But this could be easily solved by doing something like the following:

    if (dispatch_get_current_queue() == dispatch_get_main_queue()) {

        [self doUIWebKitRelatedThings];

    }

    else {

        dispatch_sync(dispatch_get_main_queue(), ^{

            [self doUIWebKitRelatedThings];

        });

    }


Thanks!

Eric Leichtenschlag

unread,
Apr 7, 2014, 7:25:07 PM4/7/14
to google-adm...@googlegroups.com
Maybe I'm misunderstanding you, but if that were possible then couldn't you do this in your own code? E.g.

    if (dispatch_get_current_queue() == dispatch_get_main_queue()) {
       
[bannerView loadRequest:request];
   
}
   
else {
        dispatch_sync
(dispatch_get_main_queue(), ^{
           
[bannerView loadRequest:request];
       
});
   
}


Thanks,
Eric

Pablo Muiña

unread,
Apr 8, 2014, 8:34:38 AM4/8/14
to google-adm...@googlegroups.com
Thanks for answering Eric. Yes, I could do that. I was asking if it could be done inside the loadRequest method for the a reason though. I've had a few main thread freezes caused generally by the first call to loadRequest. And I know that it is something wrong with loadRequest, because calling it on a background thread would prevent the app from freezing (of course, after a few seconds the app would crash, for trying to use UIWebView on a background thread).


--

---
You received this message because you are subscribed to a topic in the Google Groups "Google AdMob Ads Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-admob-ads-sdk/lD74dug6HZs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-admob-ads...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Eric Leichtenschlag

unread,
Apr 8, 2014, 4:38:22 PM4/8/14
to google-adm...@googlegroups.com
So I think the main reason the SDK requires the main thread is to set expectations. If this was moved inside of the SDK, it could confuse devs who call this on a background thread and not understand why main-thread work is being done. Forcing it to be called on the main-thread sets the expectation that main thread work will be done.

Of course, the SDK does make the ad request on a background thread, and tries to minimize the work that needs to be done on the main thread.

Are the main-thread freezes you've been experiencing reproducible?

Thanks,
Eric


On Tuesday, April 8, 2014 5:34:38 AM UTC-7, Pol Mum wrote:
Thanks for answering Eric. Yes, I could do that. I was asking if it could be done inside the loadRequest method for the a reason though. I've had a few main thread freezes caused generally by the first call to loadRequest. And I know that it is something wrong with loadRequest, because calling it on a background thread would prevent the app from freezing (of course, after a few seconds the app would crash, for trying to use UIWebView on a background thread).
On Mon, Apr 7, 2014 at 8:25 PM, Eric Leichtenschlag wrote:
Maybe I'm misunderstanding you, but if that were possible then couldn't you do this in your own code? E.g.

    if (dispatch_get_current_queue() == dispatch_get_main_queue()) {
       
[bannerView loadRequest:request];
   
}
   
else {
        dispatch_sync
(dispatch_get_main_queue(), ^{
           
[bannerView loadRequest:request];
       
});
   
}


Thanks,
Eric

On Monday, April 7, 2014 1:04:06 PM UTC-7, Pol Mum wrote:
Would it be possible to modify the iOS AdMob sdk to be able to call GADBannerView's loadRequest: method on a background thread?
I am aware that currently doing this fails because loadRequest uses the UIWebKit class, which has to be used from the main thread. But this could be easily solved by doing something like the following:

    if (dispatch_get_current_queue() == dispatch_get_main_queue()) {

        [self doUIWebKitRelatedThings];

    }

    else {

        dispatch_sync(dispatch_get_main_queue(), ^{

            [self doUIWebKitRelatedThings];

        });

    }


Thanks!

--

---
You received this message because you are subscribed to a topic in the Google Groups "Google AdMob Ads Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-admob-ads-sdk/lD74dug6HZs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.

Pablo Muiña

unread,
Apr 8, 2014, 4:52:43 PM4/8/14
to google-admob-ads-sdk
No, i'm not able to reproduce them right now. They were happening on yesterday's morning.
I was reading some more, and found a comment from a user that said that this kind of freezes were happening because of a call to canOpenURL: inside the loadRequest method, which is what was happening to me too. This user also said that he thought this only happened on the simulator.
If this is the case, then there should be no problem. I was just asking to avoid uploading a version to the AppStore which may or may not freeze.

Thanks


To unsubscribe from this group and all its topics, send an email to google-admob-ads...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages