Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Admob smart banner ads not updating on device rotation

I am trying to implement Admob's smart banner ads. I am unable to find a way to deal with updating the ad when the device is rotated. According to AdMob's docs, setting the adSize property will cause the ad to reload. This works for the standard banner ads, but it doesn't seem to work with the smart banner ads.

- (void)viewDidLoad {
    [super viewDidLoad];
    self.gadBannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerPortrait];
    self.gadBannerView.adUnitID = @"myBannerID";
    self.gadBannerView.rootViewController = self;
    [self.gadBannerView loadRequest:[GADRequest request]];
    [self.view addSubview:self.gadBannerView];
}

- (void)viewDidLayoutSubviews {
    if (self.view.bounds.size.width < self.view.bounds.size.height) {
        // portrait orientation
        self.gadBannerView.adSize = kGADAdSizeSmartBannerPortrait;
        NSLog(@"portrait banner size: %@",NSStringFromCGRect(self.gadBannerView.frame));
    } else {
        // landscape orientation
        self.gadBannerView.adSize = kGADAdSizeSmartBannerLandscape;
        NSLog(@"landscape banner size: %@",NSStringFromCGRect(self.gadBannerView.frame));
    }
}

The ads stay at the size that they were when the object is initialized. I also tried setting the GADBannerView object to nil and then initializing it again, but this didn't work.

like image 552
Bob Avatar asked May 13 '15 17:05

Bob


1 Answers

I was having the same problem with version 7.2.2 of AdMob iOS SDK.

v7.3.1 includes a fix for your problem (see AdMob iOS release notes):

Fixed a regression introduced in 7.2.0 where smart banners displayed
incorrectly in landscape on iOS 8.

like image 144
mrezk Avatar answered Oct 24 '22 07:10

mrezk