My app just got rejected because “The banner within the app should be hidden whenever ad content is not being served by iAd.” Then they supply this sample code;
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
if (self.bannerIsVisible)
{
[UIView beginAnimations:@"animateAdBannerOff" context:NULL];
// assumes the banner view is at the top of the screen.
banner.frame = CGRectOffset(banner.frame, 0, -banner.frame.size.height);
[UIView commitAnimations];
self.bannerIsVisible = NO;
}
}
Now my iAd displays at the bottom of the screen not the top. Also I wanted to take into count 3.5 vs 4 inch screens so here is my code;
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
if (self.bannerIsVisible)
{
[UIView beginAnimations:@"animateAdBannerOff" context:NULL];
CGSize result = [[UIScreen mainScreen] bounds].size;
CGFloat scale = [UIScreen mainScreen].scale;
result = CGSizeMake(result.width * scale, result.height * scale);
if(result.height == 1136){
banner.frame = CGRectOffset(banner.frame, 498, -banner.frame.size.height);
}else{
banner.frame = CGRectOffset(banner.frame, 410, -banner.frame.size.height);
}
[UIView commitAnimations];
self.bannerIsVisible = NO;
}
}
The really annoying part is that my codes works correctly on my test iPhone and in the iOS simulator.
What am I doing wrong?
If your banner is in the bottom, you should sum
banner.frame.size.heightinstead of substract to hide the banner. There is no need to do extra calculations for different screens.So, this should be enough: