@capacitor-community/admob 6.0.0 → 6.2.0-0

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.
Files changed (51) hide show
  1. package/CapacitorCommunityAdmob.podspec +1 -1
  2. package/README.md +261 -66
  3. package/android/src/main/java/com/getcapacitor/community/admob/AdMob.java +17 -0
  4. package/android/src/main/java/com/getcapacitor/community/admob/models/AdOptions.java +10 -0
  5. package/android/src/main/java/com/getcapacitor/community/admob/rewardedinterstitial/AdRewardInterstitialExecutor.java +84 -0
  6. package/android/src/main/java/com/getcapacitor/community/admob/rewardedinterstitial/RewardInterstitialAdPluginEvents.kt +12 -0
  7. package/android/src/main/java/com/getcapacitor/community/admob/rewardedinterstitial/RewardedInterstitialAdCallbackAndListeners.kt +50 -0
  8. package/android/src/main/java/com/getcapacitor/community/admob/rewardedinterstitial/models/SsvInfo.kt +20 -0
  9. package/dist/docs.json +340 -0
  10. package/dist/esm/definitions.d.ts +2 -1
  11. package/dist/esm/definitions.js.map +1 -1
  12. package/dist/esm/index.d.ts +1 -0
  13. package/dist/esm/index.js +1 -0
  14. package/dist/esm/index.js.map +1 -1
  15. package/dist/esm/reward-interstitial/index.d.ts +4 -0
  16. package/dist/esm/reward-interstitial/index.js +5 -0
  17. package/dist/esm/reward-interstitial/index.js.map +1 -0
  18. package/dist/esm/reward-interstitial/reward-interstitial-ad-options.interface.d.ts +25 -0
  19. package/dist/esm/reward-interstitial/reward-interstitial-ad-options.interface.js +2 -0
  20. package/dist/esm/reward-interstitial/reward-interstitial-ad-options.interface.js.map +1 -0
  21. package/dist/esm/reward-interstitial/reward-interstitial-ad-plugin-events.enum.d.ts +32 -0
  22. package/dist/esm/reward-interstitial/reward-interstitial-ad-plugin-events.enum.js +35 -0
  23. package/dist/esm/reward-interstitial/reward-interstitial-ad-plugin-events.enum.js.map +1 -0
  24. package/dist/esm/reward-interstitial/reward-interstitial-definitions.interface.d.ts +30 -0
  25. package/dist/esm/reward-interstitial/reward-interstitial-definitions.interface.js +2 -0
  26. package/dist/esm/reward-interstitial/reward-interstitial-definitions.interface.js.map +1 -0
  27. package/dist/esm/reward-interstitial/reward-interstitial-item.interface.d.ts +14 -0
  28. package/dist/esm/reward-interstitial/reward-interstitial-item.interface.js +2 -0
  29. package/dist/esm/reward-interstitial/reward-interstitial-item.interface.js.map +1 -0
  30. package/dist/esm/web.d.ts +2 -0
  31. package/dist/esm/web.js +12 -0
  32. package/dist/esm/web.js.map +1 -1
  33. package/dist/plugin.cjs.js +47 -0
  34. package/dist/plugin.cjs.js.map +1 -1
  35. package/dist/plugin.js +47 -0
  36. package/dist/plugin.js.map +1 -1
  37. package/package.json +10 -17
  38. package/ios/Plugin/Banner/BannerAdPluginEvents.swift +0 -8
  39. package/ios/Plugin/Banner/BannerAdSizeEnum.swift +0 -10
  40. package/ios/Plugin/Banner/BannerExecutor.swift +0 -186
  41. package/ios/Plugin/Consent/ConsentExecutor.swift +0 -87
  42. package/ios/Plugin/Helper/AuthorizationStatusEnum.swift +0 -6
  43. package/ios/Plugin/Info.plist +0 -24
  44. package/ios/Plugin/Interstitial/AdInterstitialExecutor.swift +0 -65
  45. package/ios/Plugin/Interstitial/InterstitialAdPluginEvents.swift +0 -7
  46. package/ios/Plugin/Models/FullScreenAdEventName.swift +0 -12
  47. package/ios/Plugin/Plugin.h +0 -10
  48. package/ios/Plugin/Plugin.m +0 -23
  49. package/ios/Plugin/Plugin.swift +0 -275
  50. package/ios/Plugin/Rewarded/AdRewardExecutor.swift +0 -86
  51. package/ios/Plugin/Rewarded/RewardAdPluginEvents.swift +0 -8
@@ -1,275 +0,0 @@
1
- import Foundation
2
- import Capacitor
3
- import GoogleMobileAds
4
- #if canImport(AppTrackingTransparency)
5
- import AppTrackingTransparency
6
- #endif
7
-
8
- @objc(AdMob)
9
- public class AdMob: CAPPlugin {
10
-
11
- var testingDevices: [String] = []
12
-
13
- private let bannerExecutor = BannerExecutor()
14
- private let adInterstitialExecutor = AdInterstitialExecutor()
15
- private let adRewardExecutor = AdRewardExecutor()
16
- private let consentExecutor = ConsentExecutor()
17
-
18
- /**
19
- * Enable SKAdNetwork to track conversions
20
- * https://developers.google.com/admob/ios/ios14
21
- */
22
- @objc func initialize(_ call: CAPPluginCall) {
23
- self.bannerExecutor.plugin = self
24
- self.adInterstitialExecutor.plugin = self
25
- self.adRewardExecutor.plugin = self
26
- self.consentExecutor.plugin = self
27
- self.setRequestConfiguration(call)
28
-
29
- GADMobileAds.sharedInstance().start(completionHandler: nil)
30
- call.resolve([:])
31
- }
32
-
33
- /**
34
- * DEPRECATED: It's now ship with Admob UMP Consent
35
- */
36
- @objc func requestTrackingAuthorization(_ call: CAPPluginCall) {
37
- if #available(iOS 14, *) {
38
- #if canImport(AppTrackingTransparency)
39
- ATTrackingManager.requestTrackingAuthorization(completionHandler: { _ in
40
- call.resolve([:])
41
- })
42
- #else
43
- call.resolve([:])
44
- #endif
45
- } else {
46
- call.resolve([:])
47
- }
48
- }
49
-
50
- @objc func setApplicationMuted(_ call: CAPPluginCall) {
51
- if let shouldMute = call.getBool("muted") {
52
- GADMobileAds.sharedInstance().applicationMuted = shouldMute
53
- call.resolve([:])
54
- } else {
55
- call.reject("muted property cannot be null")
56
- return
57
- }
58
- }
59
-
60
- @objc func setApplicationVolume(_ call: CAPPluginCall) {
61
- if var volume = call.getFloat("volume") {
62
- //Clamp volumes.
63
- if volume < 0.0 {volume = 0.0} else if volume > 1.0 {volume = 1.0}
64
-
65
- GADMobileAds.sharedInstance().applicationVolume = volume
66
-
67
- call.resolve([:])
68
- } else {
69
- call.reject("volume property cannot be null")
70
- return
71
- }
72
- }
73
-
74
- /**
75
- * AdMob: Banner
76
- * https://developers.google.com/ad-manager/mobile-ads-sdk/ios/banner?hl=ja
77
- */
78
- @objc func showBanner(_ call: CAPPluginCall) {
79
- let adUnitID = getAdId(call, "ca-app-pub-3940256099942544/6300978111")
80
- let request = self.GADRequestWithOption(call.getBool("npa") ?? false)
81
-
82
- DispatchQueue.main.async {
83
- self.bannerExecutor.showBanner(call, request, adUnitID)
84
- }
85
- }
86
-
87
- @objc func hideBanner(_ call: CAPPluginCall) {
88
- DispatchQueue.main.async {
89
- self.bannerExecutor.hideBanner(call)
90
- }
91
- }
92
-
93
- @objc func resumeBanner(_ call: CAPPluginCall) {
94
- DispatchQueue.main.async {
95
- self.bannerExecutor.resumeBanner(call)
96
- }
97
- }
98
-
99
- @objc func removeBanner(_ call: CAPPluginCall) {
100
- DispatchQueue.main.async {
101
- self.bannerExecutor.removeBanner(call)
102
- }
103
- }
104
-
105
- /**
106
- * AdMob: Intertitial
107
- * https://developers.google.com/admob/ios/interstitial?hl=ja
108
- */
109
- @objc func prepareInterstitial(_ call: CAPPluginCall) {
110
- let adUnitID = getAdId(call, "ca-app-pub-3940256099942544/1033173712")
111
- let request = self.GADRequestWithOption(call.getBool("npa") ?? false)
112
-
113
- DispatchQueue.main.async {
114
- self.adInterstitialExecutor.prepareInterstitial(call, request, adUnitID)
115
- }
116
- }
117
-
118
- @objc func showInterstitial(_ call: CAPPluginCall) {
119
- DispatchQueue.main.async {
120
- self.adInterstitialExecutor.showInterstitial(call)
121
- }
122
- }
123
-
124
- /**
125
- * AdMob: Rewarded Ads
126
- * https://developers.google.com/ad-manager/mobile-ads-sdk/ios/rewarded-ads?hl=ja
127
- */
128
- @objc func prepareRewardVideoAd(_ call: CAPPluginCall) {
129
- let adUnitID = getAdId(call, "ca-app-pub-3940256099942544/1712485313")
130
- let request = self.GADRequestWithOption(call.getBool("npa") ?? false)
131
-
132
- DispatchQueue.main.async {
133
- self.adRewardExecutor.prepareRewardVideoAd(call, request, adUnitID)
134
- }
135
- }
136
-
137
- @objc func showRewardVideoAd(_ call: CAPPluginCall) {
138
- DispatchQueue.main.async {
139
- self.adRewardExecutor.showRewardVideoAd(call)
140
- }
141
- }
142
-
143
- @objc func trackingAuthorizationStatus(_ call: CAPPluginCall) {
144
- DispatchQueue.main.async {
145
- if #available(iOS 14, *) {
146
- switch ATTrackingManager.trackingAuthorizationStatus {
147
- case .authorized:
148
- call.resolve(["status": AuthorizationStatusEnum.Authorized.rawValue])
149
- break
150
- case .denied:
151
- call.resolve(["status": AuthorizationStatusEnum.Denied.rawValue])
152
- break
153
- case .restricted:
154
- call.resolve(["status": AuthorizationStatusEnum.Restricted.rawValue])
155
- break
156
- case .notDetermined:
157
- call.resolve(["status": AuthorizationStatusEnum.NotDetermined.rawValue])
158
- break
159
- @unknown default:
160
- call.reject("trackingAuthorizationStatus can't get status")
161
- }
162
- } else {
163
- call.resolve(["status": AuthorizationStatusEnum.Authorized])
164
- }
165
- }
166
- }
167
-
168
- /**
169
- * Admob: User Message Platform
170
- * https://support.google.com/admob/answer/10113005?hl=en
171
- */
172
- @objc func requestConsentInfo(_ call: CAPPluginCall) {
173
- let debugGeography = call.getInt("debugGeography", 0)
174
-
175
- let testDeviceJSArray = call.getArray("testDeviceIdentifiers") ?? []
176
- var testDeviceIdentifiers: [String] = []
177
- if testDeviceJSArray.count > 0 {
178
- for deviceId in testDeviceJSArray {
179
- if let name = deviceId as? String {
180
- testDeviceIdentifiers.append(name)
181
- }
182
- }
183
- }
184
-
185
- let tagForUnderAgeOfConsent = call.getBool("tagForUnderAgeOfConsent", false)
186
-
187
- DispatchQueue.main.async {
188
- self.consentExecutor.requestConsentInfo(call, debugGeography, testDeviceIdentifiers, tagForUnderAgeOfConsent)
189
- }
190
- }
191
-
192
- @objc func showConsentForm(_ call: CAPPluginCall) {
193
- DispatchQueue.main.async {
194
- self.consentExecutor.showConsentForm(call)
195
- }
196
- }
197
-
198
- @objc func resetConsentInfo(_ call: CAPPluginCall) {
199
- DispatchQueue.main.async {
200
- self.consentExecutor.resetConsentInfo(call)
201
- }
202
- }
203
-
204
- private func getAdId(_ call: CAPPluginCall, _ testingID: String) -> String {
205
- let adUnitID = call.getString("adId") ?? testingID
206
- let isTest = call.getBool("isTesting") ?? false
207
- if isTest {
208
- return testingID
209
- }
210
- return adUnitID
211
- }
212
-
213
- private func GADRequestWithOption(_ npa: Bool) -> GADRequest {
214
- let request = GADRequest()
215
-
216
- if npa {
217
- let extras = GADExtras()
218
- extras.additionalParameters = ["npa": "1"]
219
- request.register(extras)
220
- }
221
-
222
- return request
223
- }
224
-
225
- /**
226
- * https://developers.google.com/admob/ios/targeting?hl=ja
227
- */
228
- private func setRequestConfiguration(_ call: CAPPluginCall) {
229
-
230
- if call.getBool("initializeForTesting") ?? false {
231
- GADMobileAds.sharedInstance().requestConfiguration.testDeviceIdentifiers = call.getArray("testingDevices", String.self) ?? []
232
- }
233
-
234
- if call.getBool("tagForChildDirectedTreatment") == true {
235
- GADMobileAds.sharedInstance().requestConfiguration.tagForChildDirectedTreatment = true
236
- }
237
-
238
- if call.getBool("tagForUnderAgeOfConsent") == true {
239
- GADMobileAds.sharedInstance().requestConfiguration.tagForUnderAgeOfConsent = true
240
- }
241
-
242
- if call.getString("maxAdContentRating") != nil {
243
- switch call.getString("maxAdContentRating") {
244
- case "General":
245
- GADMobileAds.sharedInstance().requestConfiguration.maxAdContentRating =
246
- GADMaxAdContentRating.general
247
- case "ParentalGuidance":
248
- GADMobileAds.sharedInstance().requestConfiguration.maxAdContentRating =
249
- GADMaxAdContentRating.parentalGuidance
250
- case "Teen":
251
- GADMobileAds.sharedInstance().requestConfiguration.maxAdContentRating =
252
- GADMaxAdContentRating.teen
253
- case "MatureAudience":
254
- GADMobileAds.sharedInstance().requestConfiguration.maxAdContentRating =
255
- GADMaxAdContentRating.matureAudience
256
- default:
257
- print("maxAdContentRating can't find value")
258
- }
259
- }
260
-
261
- }
262
-
263
- func getRootVC() -> UIViewController? {
264
- var window: UIWindow? = UIApplication.shared.delegate?.window ?? nil
265
-
266
- if window == nil {
267
- let scene: UIWindowScene? = UIApplication.shared.connectedScenes.first as? UIWindowScene
268
- window = scene?.windows.filter({$0.isKeyWindow}).first
269
- if window == nil {
270
- window = scene?.windows.first
271
- }
272
- }
273
- return window?.rootViewController
274
- }
275
- }
@@ -1,86 +0,0 @@
1
- import Foundation
2
- import Capacitor
3
- import GoogleMobileAds
4
-
5
- class AdRewardExecutor: NSObject, GADFullScreenContentDelegate {
6
- public weak var plugin: AdMob?
7
- var rewardedAd: GADRewardedAd!
8
-
9
- func prepareRewardVideoAd(_ call: CAPPluginCall, _ request: GADRequest, _ adUnitID: String) {
10
- GADRewardedAd.load(
11
- withAdUnitID: adUnitID,
12
- request: request,
13
- completionHandler: { (ad, error) in
14
- if let error = error {
15
- NSLog("Rewarded ad failed to load with error: \(error.localizedDescription)")
16
- self.plugin?.notifyListeners(RewardAdPluginEvents.FailedToLoad.rawValue, data: [
17
- "code": 0,
18
- "message": error.localizedDescription
19
- ])
20
- call.reject("Loading failed")
21
- return
22
- }
23
-
24
- self.rewardedAd = ad
25
-
26
- if let providedOptions = call.getObject("ssv") {
27
- let ssvOptions = GADServerSideVerificationOptions()
28
-
29
- if let customData = providedOptions["customData"] as? String {
30
- NSLog("Sending Custom Data: \(customData) to SSV callback")
31
- ssvOptions.customRewardString = customData
32
- }
33
-
34
- if let userId = providedOptions["userId"] as? String {
35
- NSLog("Sending UserId: \(userId) to SSV callback")
36
- ssvOptions.userIdentifier = userId
37
- }
38
-
39
- self.rewardedAd?.serverSideVerificationOptions = ssvOptions
40
- }
41
-
42
- self.rewardedAd?.fullScreenContentDelegate = self
43
- self.plugin?.notifyListeners(RewardAdPluginEvents.Loaded.rawValue, data: [
44
- "adUnitId": adUnitID
45
- ])
46
- call.resolve([
47
- "adUnitId": adUnitID
48
- ])
49
- }
50
- )
51
- }
52
-
53
- func showRewardVideoAd(_ call: CAPPluginCall) {
54
- if let rootViewController = plugin?.getRootVC() {
55
- if let ad = self.rewardedAd {
56
- ad.present(fromRootViewController: rootViewController,
57
- userDidEarnRewardHandler: {
58
- let reward = ad.adReward
59
- self.plugin?.notifyListeners(RewardAdPluginEvents.Rewarded.rawValue, data: ["type": reward.type, "amount": reward.amount])
60
- call.resolve(["type": reward.type, "amount": reward.amount])
61
- }
62
- )
63
- } else {
64
- call.reject("Reward Video is Not Ready Yet")
65
- }
66
- }
67
- }
68
-
69
- public func ad(_ ad: GADFullScreenPresentingAd, didFailToPresentFullScreenContentWithError error: Error) {
70
- NSLog("RewardFullScreenDelegate Ad failed to present full screen content with error \(error.localizedDescription).")
71
- self.plugin?.notifyListeners(RewardAdPluginEvents.FailedToShow.rawValue, data: [
72
- "code": 0,
73
- "message": error.localizedDescription
74
- ])
75
- }
76
-
77
- public func adWillPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) {
78
- NSLog("RewardFullScreenDelegate Ad did present full screen content.")
79
- self.plugin?.notifyListeners(RewardAdPluginEvents.Showed.rawValue, data: [:])
80
- }
81
-
82
- public func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) {
83
- NSLog("RewardFullScreenDelegate Ad did dismiss full screen content.")
84
- self.plugin?.notifyListeners(RewardAdPluginEvents.Dismissed.rawValue, data: [:])
85
- }
86
- }
@@ -1,8 +0,0 @@
1
- public enum RewardAdPluginEvents: String {
2
- case Loaded = "onRewardedVideoAdLoaded"
3
- case FailedToLoad = "onRewardedVideoAdFailedToLoad"
4
- case Showed = "onRewardedVideoAdShowed"
5
- case FailedToShow = "onRewardedVideoAdFailedToShow"
6
- case Dismissed = "onRewardedVideoAdDismissed"
7
- case Rewarded = "onRewardedVideoAdReward"
8
- }