Admob-SwiftUI

1.0.2

This library helps you to easily integrate the Admob SDK in your SwiftUI app. It is a wrapper around the Google Mobile Ads SDK for iOS. It provides a SwiftUI view that you can use to display banner ads in your app above your tabbar.
0xWDG/Admob-SwiftUI

What's New

1.0.2

2026-06-15T19:06:35Z

What's Changed

  • Consolidate changes: introduce ad unit ID handling, banner state structures, and InterstitialAdEvent enum. Enhance lifecycle management and testing for SwiftUI ad components.
  • Generate DOCC documentation by @0xWDG in #1

Full Changelog: 1.0.0...1.0.2

Admob for SwiftUI

This library helps you to easily integrate the Admob SDK in your SwiftUI app. It is a wrapper around the Google Mobile Ads SDK for iOS. It provides a SwiftUI view that you can use to display banner ads in your app above your tabbar. See my blog post for more information: https://wesleydegroot.nl/blog/post/Admob-in-SwiftUI

Requirements

  • Swift 5.9+ (Xcode 15+)
  • iOS 15+

Installation

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

Usage

struct MyApp: App {
    @StateObject var adHelper = AdHelper(
        adUnitID: "YOUR-AD-UNIT-ID"
    )

    var body: some Scene {
        WindowGroup {
            ContentView()
                .environmentObject(adHelper)
        }
    }
}

struct ContentView: View {
    @EnvironmentObject
    var adHelper: AdHelper

    var body: some View {
        AdView {
            TabView {
                UpdateConsent()
                    .tabItem {
                        Image(systemName: "2.square.fill")
                        Text("Second")
                    }

                SecondView()
                    .tabItem {
                        Image(systemName: "1.square.fill")
                        Text("First")
                    }
            }
        }
    }
}

struct SecondView: View {
    @EnvironmentObject
    var adHelper: AdHelper

    var body: some View {
        BannerView() // A banner view.
    }
}

Request App Tracking Transparency authorization explicitly from your app after showing any explanatory UI:

let status = await AdTrackingAuthorization.request()

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()
                }
            }
        }
    }
}

Contact

๐Ÿฆ‹ @0xWDG ๐Ÿ˜ mastodon.social/@0xWDG ๐Ÿฆ @0xWDG ๐Ÿงต @0xWDG ๐ŸŒ wesleydegroot.nl ๐Ÿค– Discord

Interested learning more about Swift? Check out my blog.

Description

  • Swift Tools 5.5.0
View More Packages from this Author

Dependencies

Last updated: Sun Jun 21 2026 01:36:17 GMT-0900 (Hawaii-Aleutian Daylight Time)