最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

ios - SwiftUI AdMob - Invalid ad width or height: (0, 0) - Stack Overflow

programmeradmin3浏览0评论
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?

发布评论

评论列表(0)

  1. 暂无评论