Admob-SwiftUI

1.0.0

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.0

2024-02-23T13:41:32Z

Admob for SwiftUI

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

Contact

We can get in touch via Twitter/X, Discord, Mastodon, Threads, Bluesky.

Alternatively you can visit my Website or my Blog

Description

  • Swift Tools 5.5.0
View More Packages from this Author

Dependencies

Last updated: Thu Nov 14 2024 16:11:48 GMT-1000 (Hawaii-Aleutian Standard Time)