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
版权声明:本文标题:ios - SwiftUI AdMob - Invalid ad width or height: (0, 0) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744632572a2616630.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论