@capgo/capacitor-admob 7.1.1 → 7.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CapgoCapacitorAdmob.podspec +1 -0
- package/Package.swift +4 -2
- package/README.md +102 -44
- package/android/src/main/kotlin/admob/plus/capacitor/AdMobPlusPlugin.kt +12 -0
- package/dist/docs.json +283 -51
- package/dist/esm/definitions.d.ts +206 -3
- package/dist/esm/definitions.js +19 -0
- package/dist/esm/definitions.js.map +1 -1
- package/dist/plugin.cjs.js +19 -0
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +19 -0
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/AdmobPlusPlugin/AdmobPlusPlugin.swift +223 -10
- package/ios/Sources/AdmobPlusPlugin/BannerAd.swift +143 -0
- package/ios/Sources/AdmobPlusPlugin/Generated.swift +40 -0
- package/ios/Sources/AdmobPlusPlugin/Helper.swift +68 -0
- package/ios/Sources/AdmobPlusPlugin/InterstitialAd.swift +92 -0
- package/ios/Sources/AdmobPlusPlugin/RewardedAd.swift +102 -0
- package/ios/Sources/AdmobPlusPlugin/RewardedInterstitialAd.swift +102 -0
- package/package.json +1 -1
- package/ios/Sources/AdmobPlusPlugin/AdmobPlus.swift +0 -8
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import UIKit
|
|
3
|
+
import GoogleMobileAds
|
|
4
|
+
import Capacitor
|
|
5
|
+
|
|
6
|
+
class RewardedInterstitialAd: NSObject, Ad {
|
|
7
|
+
let id: Int
|
|
8
|
+
let adUnitId: String
|
|
9
|
+
private var rewardedInterstitialAd: GADRewardedInterstitialAd?
|
|
10
|
+
private weak var plugin: AdmobPlusPlugin?
|
|
11
|
+
|
|
12
|
+
var isLoaded: Bool {
|
|
13
|
+
return rewardedInterstitialAd != nil
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
init(id: Int, adUnitId: String, plugin: AdmobPlusPlugin) {
|
|
17
|
+
self.id = id
|
|
18
|
+
self.adUnitId = adUnitId
|
|
19
|
+
self.plugin = plugin
|
|
20
|
+
super.init()
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
func load(completion: @escaping (Error?) -> Void) {
|
|
24
|
+
let request = AdMobHelper.buildAdRequest()
|
|
25
|
+
|
|
26
|
+
GADRewardedInterstitialAd.load(withAdUnitID: adUnitId, request: request) { [weak self] ad, error in
|
|
27
|
+
guard let self = self else { return }
|
|
28
|
+
|
|
29
|
+
if let error = error {
|
|
30
|
+
self.plugin?.notifyListeners(Events.rewardedInterstitialLoadFail, data: [
|
|
31
|
+
"id": self.id,
|
|
32
|
+
"error": error.localizedDescription
|
|
33
|
+
])
|
|
34
|
+
completion(error)
|
|
35
|
+
return
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
self.rewardedInterstitialAd = ad
|
|
39
|
+
self.rewardedInterstitialAd?.fullScreenContentDelegate = self
|
|
40
|
+
|
|
41
|
+
self.plugin?.notifyListeners(Events.rewardedInterstitialLoad, data: ["id": self.id])
|
|
42
|
+
completion(nil)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
func show(completion: @escaping (Error?) -> Void) {
|
|
47
|
+
DispatchQueue.main.async { [weak self] in
|
|
48
|
+
guard let self = self, let rewardedInterstitialAd = self.rewardedInterstitialAd else {
|
|
49
|
+
completion(AdMobError.adNotLoaded)
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
guard let viewController = self.plugin?.bridge?.viewController else {
|
|
54
|
+
completion(AdMobError.unknown("Unable to access view controller"))
|
|
55
|
+
return
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
rewardedInterstitialAd.present(fromRootViewController: viewController) { [weak self] in
|
|
59
|
+
guard let self = self else { return }
|
|
60
|
+
let reward = rewardedInterstitialAd.adReward
|
|
61
|
+
self.plugin?.notifyListeners(Events.rewardedInterstitialReward, data: [
|
|
62
|
+
"id": self.id,
|
|
63
|
+
"reward": [
|
|
64
|
+
"amount": reward.amount.intValue,
|
|
65
|
+
"type": reward.type
|
|
66
|
+
]
|
|
67
|
+
])
|
|
68
|
+
}
|
|
69
|
+
completion(nil)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
func destroy() {
|
|
74
|
+
rewardedInterstitialAd = nil
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
extension RewardedInterstitialAd: GADFullScreenContentDelegate {
|
|
79
|
+
func adDidRecordImpression(_ ad: GADFullScreenPresentingAd) {
|
|
80
|
+
plugin?.notifyListeners(Events.rewardedInterstitialImpression, data: ["id": id])
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
func adDidRecordClick(_ ad: GADFullScreenPresentingAd) {
|
|
84
|
+
plugin?.notifyListeners(Events.adClick, data: ["id": id])
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
func ad(_ ad: GADFullScreenPresentingAd, didFailToPresentFullScreenContentWithError error: Error) {
|
|
88
|
+
plugin?.notifyListeners(Events.rewardedInterstitialShowFail, data: [
|
|
89
|
+
"id": id,
|
|
90
|
+
"error": error.localizedDescription
|
|
91
|
+
])
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
func adWillPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) {
|
|
95
|
+
plugin?.notifyListeners(Events.rewardedInterstitialShow, data: ["id": id])
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) {
|
|
99
|
+
plugin?.notifyListeners(Events.rewardedInterstitialDismiss, data: ["id": id])
|
|
100
|
+
rewardedInterstitialAd = nil
|
|
101
|
+
}
|
|
102
|
+
}
|
package/package.json
CHANGED