Search code examples
swiftadmob

Swift AdMob ad wrong size


I'm using AdMobs smart banner in may app, I did everything as suggest in Googles Getting Started except banner size isn't fixes 320x50, its screen widthx50. In auto layout I added 1 constrain for horizontal center and 1 for screen width. If I run that on simulator I works great but on device I'm getting this error:

<Google> Unable to set adSize property. Not enough space to show ad with custom size, {600, 50}. Please use a size that fits the current screen bounds of {320, 568}.
<Google> To get test ads on this device, call: request.testDevices = @[ @"bb3f8f97887" ];
<Google> Unable to set adSize property. Not enough space to show ad with custom size, {600, 50}. Please use a size that fits the current screen bounds of {320, 568}.
<Google> Invalid Request. Ad size will not fit on screen

If I log GADBannerView view size I'm getting this (running on iPhone 5):

Size:  (0.0, 0.0, 320.0, 50.0)

                                                  

This is my code:

@IBOutlet weak var bannerView: GADBannerView!

bannerView.adUnitID = "ca-app-pub-394/216"
bannerView.adSize = kGADAdSizeSmartBannerPortrait
bannerView.rootViewController = self
print("Size: ",bannerView.bounds)
bannerView.loadRequest(GADRequest())

These are my constrains                                                             


Solution

  • You need to add a width constraint.

    Ctrl-Drag from the AdView to the parent and select Equal Widths.