See my blog post for more information: https://wesleydegroot.nl/blog/post/Admob-in-SwiftUI
- Swift 5.9+ (Xcode 15+)
- iOS 15+
Install using Swift Package Manager
dependencies: [
.package(url: "https://github.com/0xWDG/Admob-SwiftUI.git", .branch("main")),
],
targets: [
.target(name: "MyTarget", dependencies: [
.product(name: "Admob_SwiftUI", package: "Admob_SwiftUI"),
]),
]
And import it:
import Admob_SwiftUI
struct ContentView: View {
@ObservedObject var adHelper = AdHelper(
adUnitId: "YOUR-AD-UNIT-ID"
)
AdView {
TabView {
Text("First View")
.tabItem {
Image(systemName: "1.square.fill")
Text("First")
}
UpdateConsent()
.tabItem {
Image(systemName: "2.square.fill")
Text("Second")
}
}
}
.environmentObject(adHelper)
}
Reset/Update Consent
struct UpdateConsent: View {
@EnvironmentObject
private var adHelper: AdHelper
var body: some View {
ScrollView {
VStack {
Button("Reset consent", role: .destructive) {
adHelper.resetConsent()
}
Button("Update Consent") {
adHelper.updateConsent()
}
}
}
}
}
We can get in touch via Twitter/X, Discord, Mastodon, Threads, Bluesky.