iosswiftxcodeswiftuiadmob

AdMob: Invalid frame size


I am trying to implement ads in my app, code and app running perfectly, but ads not. I am getting an error in console

<Google> Invalid Request. Invalid ad width or height: (0, 0)
bannerView:didFailToReceiveAdWithError: Invalid ad width or height: (0, 0)

Even if I Add frame width and height. Here is my simple code for test:

            HStack {
                Spacer()
                BannerAd(unitID:
                            "ca-app-pub ...")
                .frame(width: 320, height: 50)
            }

I tried adding frame, changing width and height but still getting this error.


Solution

  • I found a solution by myself. I just had BannerAd without anything. If anyone are struggling with this try to do that under the text:

    VStack { 
      Text("") 
      BannerAd(unitID:"ca-app-pub ...")
    }