admin管理员组

文章数量:1406937

struct BetweenMemesBannerView : View {
    
    @State var isLoaded: Bool = true
    
    var body : some View{
        VStack(spacing: 0){
            if(isLoaded){
                AdView(isLoaded: self.$isLoaded, adType: "between")
                    .frame(width: 320, height: 250)
            }
        }
    }
}

struct AdView: UIViewRepresentable {
    
    @Binding var isLoaded: Bool
    var adType: String
    
    class Coordinator: NSObject, GADBannerViewDelegate {
        
        let adView: AdView
        init(_ adView: AdView) {
            self.adView = adView
        }
        
        func bannerView(_ bannerView: GADBannerView, didFailToReceiveAdWithError error: Error) {
            print("Ad failed to load: \(error.localizedDescription)")
            adView.isLoaded = false
        }
    }

    func makeCoordinator() -> Coordinator {
        Coordinator(self)
    }

    func makeUIView(context: Context) -> GADBannerView {
        let banner = GADBannerView(adSize: GADAdSizeMediumRectangle)
        banner.adUnitID = "ca-app-pub-3940256099942544/2435281174" // debug
        banner.delegate = context.coordinator
        banner.load(GADRequest())
        banner.backgroundColor = .black
        return banner
    }

    func updateUIView(_ uiView: GADBannerView, context: Context) {
        // In this case, no update is needed.
    }
}

I get the error:

Invalid ad width or height: (0, 0)

How to fix this?

本文标签: iosSwiftUI AdMobInvalid ad width or height (00)Stack Overflow