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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With