Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google AdMob GADBannerView first request takes long time and freezes UI

Tags:

ios

admob

banner

I'm using Google AdMob SDK (latest one downloaded just recently) in my app.

When my app launches it freezes for 4-5 seconds, until the ad is loaded and displayed. Afterwards it runs smoothly. When I comment out the banner request line, the app starts normally.

I have made a custom helper class, in which I have the following code.

- (void) getGoogleBanner:(UIViewController *) targetController
{
    self.googleBannerView.rootViewController = targetController;
    [self.googleBannerView.rootViewController.view addSubview:self.googleBannerView];
    [self.googleBannerView setDelegate:self];
    GADRequest* request = [GADRequest request];
    [self.googleBannerView loadRequest:request];
}

where

  • googleBannerView is a property of my class, and has the type GADBannerView
  • I set the frame size and ad unit ID beforehand properly
  • targetController is the controller I want to add the banner to
  • I call the [CustomClass getGoogleBanner:self] method in viewDidAppear of various different controllers and successfully display the banner, except that first load issue.

I'd like to know if anyone has run into this problem, and how it is solved. I'm open to any ideas that would remove the freezing issue. I tried to running the code to a background thread, but I failed because I'm not very experienced with it.

Any help is much appreciated, thanks in advance.

like image 840
Murat Ögat Avatar asked Jan 23 '13 22:01

Murat Ögat


1 Answers

I've got the issue only when running in the simulator, so if this is the case, you shouldn't probably worry.

From what I could find, when calling the loadRequest method, the framework will also call canOpenURL: method (UIApplication). From some tests that I ran (on both simulator and iOS devices with 5.1.1 and 6.1.3), canOpenURL occasionally freezes for few seconds on the simulator (once it took it 20 seconds to return), however, works well on the devices.

like image 57
alex-i Avatar answered Oct 12 '22 18:10

alex-i