Skip to content

Commit 9378c0c

Browse files
2semclaude
andauthored
docs: add README (#18)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 709c444 commit 9378c0c

File tree

1 file changed

+137
-0
lines changed

1 file changed

+137
-0
lines changed

README.md

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# GADManager
2+
3+
A Swift library for managing Google Mobile Ads with time-based throttling and lifecycle management.
4+
5+
## Requirements
6+
7+
- iOS 12.0+
8+
- Swift 5.10+
9+
10+
## Installation
11+
12+
### Swift Package Manager
13+
14+
```swift
15+
.package(url: "https://github.com/2sem/GADManager.git", from: "1.4.0")
16+
```
17+
18+
## Setup
19+
20+
Add your ad unit IDs to `Info.plist` under the key `GADUnitIdentifiers` as a `[String: String]` dictionary:
21+
22+
```xml
23+
<key>GADUnitIdentifiers</key>
24+
<dict>
25+
<key>interstitial</key>
26+
<string>ca-app-pub-xxxx/xxxx</string>
27+
<key>opening</key>
28+
<string>ca-app-pub-xxxx/xxxx</string>
29+
<key>rewarded</key>
30+
<string>ca-app-pub-xxxx/xxxx</string>
31+
</dict>
32+
```
33+
34+
Define an enum for your ad units:
35+
36+
```swift
37+
enum AdUnit: String {
38+
case interstitial
39+
case opening
40+
case rewarded
41+
}
42+
```
43+
44+
## Usage
45+
46+
### Initialization
47+
48+
```swift
49+
let adManager = GADManager<AdUnit>(window)
50+
adManager.delegate = self
51+
```
52+
53+
### Interstitial
54+
55+
```swift
56+
// Prepare (load)
57+
adManager.prepare(interstitialUnit: .interstitial, interval: 60 * 60)
58+
59+
// Show
60+
adManager.show(unit: .interstitial) { unit, _, shown in
61+
// shown: true if ad was displayed and dismissed
62+
}
63+
```
64+
65+
### App Open
66+
67+
```swift
68+
adManager.prepare(openingUnit: .opening)
69+
70+
adManager.show(unit: .opening, needToWait: true) { unit, _, shown in }
71+
```
72+
73+
### Rewarded
74+
75+
```swift
76+
adManager.prepare(rewardUnit: .rewarded)
77+
78+
adManager.show(unit: .rewarded) { unit, obj, rewarded in
79+
if rewarded, let reward = obj as? GoogleMobileAds.AdReward {
80+
print("Earned \(reward.amount) \(reward.type)")
81+
}
82+
}
83+
```
84+
85+
### Banner
86+
87+
```swift
88+
if let bannerView = adManager.prepare(bannerUnit: .banner) {
89+
bannerView.rootViewController = self
90+
view.addSubview(bannerView)
91+
bannerView.load(GoogleMobileAds.Request())
92+
}
93+
```
94+
95+
### ATT Permission
96+
97+
```swift
98+
if #available(iOS 14, *) {
99+
adManager.requestPermission { status in
100+
// load ads after permission resolved
101+
}
102+
}
103+
```
104+
105+
## Delegate
106+
107+
```swift
108+
extension MyClass: GADManagerDelegate {
109+
// Required: persist last shown time per unit
110+
func GAD<E>(manager: GADManager<E>, lastShownTimeForUnit unit: E) -> Date {
111+
return UserDefaults.standard.object(forKey: unit.rawValue) as? Date ?? .distantPast
112+
}
113+
114+
func GAD<E>(manager: GADManager<E>, updatShownTimeForUnit unit: E, showTime time: Date) {
115+
UserDefaults.standard.set(time, forKey: unit.rawValue)
116+
}
117+
118+
// Optional
119+
func GAD<E>(manager: GADManager<E>, didEarnRewardForUnit unit: E, reward: GoogleMobileAds.AdReward) {
120+
print("Reward earned: \(reward.amount) \(reward.type)")
121+
}
122+
123+
func GAD<E>(manager: GADManager<E>, willPresentADForUnit unit: E) {}
124+
func GAD<E>(manager: GADManager<E>, didDismissADForUnit unit: E) {}
125+
}
126+
```
127+
128+
## Timing
129+
130+
| Constant | Default | Description |
131+
|---|---|---|
132+
| `defaultInterval` | 1 hour | Minimum time between interstitial/opening shows |
133+
| `opeingExpireInterval` | 4 hours (5 min DEBUG) | App Open ad validity after loading |
134+
135+
## License
136+
137+
MIT

0 commit comments

Comments
 (0)