Search code examples
iosframeiadadbannerview

Frame for "Banner View" will be different at run time. iAd works for largest screen but blank on smaller ones


I've nearly finished my app and the only issue I have is that my iAd banner view will only show on the largest screen. I have set the constraints so the iAd will fit nicely on smaller screens but when I run it on any size other than the largest, all I see is a white box.

The current code I have is:

-(void)bannerViewDidLoadAd:(ADBannerView *)banner {

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[banner setAlpha:1];
[UIView commitAnimations];

}


-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {


[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[banner setAlpha:0];
[UIView commitAnimations];


}

I'm wondering if I should add a line of code to the bannerViewDidLoadAd to say something about the frame size.

The error I keep getting is:

Frame for "banner view" will be different at run time.

Size will be (320,50) at runtime but is (480,60) in the canvas.

The iAd framework has been imported and the add delegated. It's within a scroll view if that makes any difference.

All my constraints are fine it's just this frame size that's the issue. if i attempt to update frames nothing happens.

Any help would be greatly appreciated.

Thanks.


Solution

  • Sounds like you have trailing and leading constraints set on your ADBannerView.

    Your ADBannerView will know which device it is on and set the dimensions of the ADBannerView accordingly. You should just let Auto Layout know where you want your ad to be. For example, if you wanted your ADBannerView to be at the bottom of your view then you would pin it to the bottom of your view with Bottom Space to: Bottom Layout Guide and align it to Align Center X to: Superview.

    Also, don't use the beginAnimations:context: method. From UIView Class Reference:

    Use of this method is discouraged in iOS 4.0 and later. You should use the block-based animation methods to specify your animations instead.

    Using block-based animations, your delegate methods would end up looking like this:

    -(void)bannerViewDidLoadAd:(ADBannerView *)banner {
        [UIView animateWithDuration:1.0 animations:^{
            banner.alpha = 1.0;
        }];
    }
    
    -(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
        [UIView animateWithDuration:1.0 animations:^{
            banner.alpha = 0.0;
        }];
    }