Программируем под IOS
Anonymous
Swiftui Admob - неверная ширина или высота AD: (0, 0)
Сообщение
Anonymous » 15 мар 2025, 00:14
Код: Выделить всё
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.
}
}
< /code>
Я получаю ошибку: < /p>
Invalid ad width or height: (0, 0)
Как это исправить?
Подробнее здесь:
https://stackoverflow.com/questions/795 ... height-0-0
1741986842
Anonymous
[code]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. } } < /code> Я получаю ошибку: < /p> Invalid ad width or height: (0, 0) [/code] Как это исправить? Подробнее здесь: [url]https://stackoverflow.com/questions/79510234/swiftui-admob-invalid-ad-width-or-height-0-0[/url]