I am trying to implement Admob's "smart" banners in my iOS app. But I am unable to find a way to deal with updating the ad when the device is rotated. I made a simple test app to try to find a way to make this work. According to the docs, setting the adSize property will cause the ad to reload. Although this works for the standard ads, it doesn't seem to work with the smart ones.
[super viewDidLoad]; self.gadBannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerPortrait]; self.gadBannerView.adUnitID = @"ca-app-pub-3940256099942544/2934735716"; 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; } else {
// landscape orientation self.gadBannerView.adSize = kGADAdSizeSmartBannerLandscape; }
}
The ads stay at the size that they were when the object is init'd. I also tried setting the GADBannerView object to nil and then initing it again - also didn't work.
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInt duration:(NSTimeInterval)duration { if (UIInterfaceOrientationIsLandscape(toInt)) { self.adBanner.adSize = kGADAdSizeSmartBannerLandscape; } else { self.adBanner.adSize = kGADAdSizeSmartBannerPortrait; } }
<Google> Unable to set adSize property. Not enough space to show ad with custom size, {959, 32}. Please use a size that fits the current screen bounds of {375, 667}.