https://github.com/0xwdg/admob-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.
https://github.com/0xwdg/admob-swiftui
admob ads google hacktoberfest package spm swift swift-ui swiftlang swiftpm swiftui
Last synced: about 1 month ago
JSON representation
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.
- Host: GitHub
- URL: https://github.com/0xwdg/admob-swiftui
- Owner: 0xWDG
- License: mit
- Created: 2024-02-11T12:39:00.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-02-20T20:19:21.000Z (over 1 year ago)
- Last Synced: 2025-10-11T02:46:19.670Z (8 months ago)
- Topics: admob, ads, google, hacktoberfest, package, spm, swift, swift-ui, swiftlang, swiftpm, swiftui
- Language: Swift
- Homepage: https://0xwdg.github.io/Admob-SwiftUI/
- Size: 2.05 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
# 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
```swift
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:
```swift
import Admob_SwiftUI
```
# Usage
```swift
struct MyApp: App {
@ObservedObject 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.
}
}
```
**Reset/Update Consent**
```Swift
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](https://bsky.app/profile/0xWDG.bsky.social)
๐ [mastodon.social/@0xWDG](https://mastodon.social/@0xWDG)
๐ฆ [@0xWDG](https://x.com/0xWDG)
๐งต [@0xWDG](https://www.threads.net/@0xWDG)
๐ [wesleydegroot.nl](https://wesleydegroot.nl)
๐ค [Discord](https://discordapp.com/users/918438083861573692)
Interested learning more about Swift? [Check out my blog](https://wesleydegroot.nl/blog/).