简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM