Код: Выделить всё
struct BottomBannerView : View {
@State var isLoaded: Bool = true
var body : some View{
AdViewBottom(isLoaded: self.$isLoaded)
.frame(width: 320, height: isLoaded ? 50 : 0)
}
}
struct AdViewBottom: UIViewRepresentable {
@Binding var isLoaded: Bool
class Coordinator: NSObject, GADBannerViewDelegate {
func bannerView(_ bannerView: GADBannerView, didFailToReceiveAdWithError error: Error) {
print("Ad failed to load: \(error.localizedDescription)")
isLoaded = false // HOW???
}
}
func makeCoordinator() -> Coordinator {
Coordinator()
}
func makeUIView(context: Context) -> GADBannerView {
let banner = GADBannerView(adSize: GADAdSizeBanner)
banner.adUnitID = "ca-app-pub-xxx~xxxx"
// banner.rootViewController = UIApplication.shared.windows.first?.rootViewController // The root view controller is needed to present full screen content.
banner.delegate = context.coordinator
banner.load(GADRequest())
banner.backgroundColor = .black
return banner
}
// SwiftUI calls this method to update the GADBannerView.
func updateUIView(_ uiView: GADBannerView, context: Context) {
// In this case, no update is needed.
}
}
Подробнее здесь: https://stackoverflow.com/questions/795 ... oad-failed