0

I want to show the AdMob banner on all view in SwiftUI above the TabView. Any ideas on how should I do it?

BannerAdView(adUnit: .banner, adFormat: .adaptiveBanner)

If I copy-paste and put it in a ZStack in each view, it always reloads the ad/change to a new ad. I want to avoid this.

sandorb
  • 479
  • 1
  • 7
  • 17

1 Answers1

1

You will just have to use your BannerAdView once in your top most view. There you can use a ZStack and then use your ContentView there.

struct WrapperView: View {  
    var body: some View {
        ZStack {
            BannerAdView(adUnit: .banner, adFormat: .adaptiveBanner)
            ContentView()
        }
    }
}

struct ContentView: View {
    var body: some View {
        Text("Hello")
        // Here comes your Content and Tab Views
    }
}
davidev
  • 7,694
  • 5
  • 21
  • 56
  • Thanks, it works, but I wanted to show it above the TabView, and found the answer for that: https://stackoverflow.com/questions/59969911/programmatically-detect-tab-bar-or-tabview-height-in-swiftui – sandorb Apr 06 '21 at 12:24
  • But Cannot find 'BannerAdView' in scope – Gank Jul 16 '23 at 14:13