cordova-admob-tomitank 1.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 (114) hide show
  1. package/CHANGELOG.md +0 -0
  2. package/README.md +17 -0
  3. package/esm/admob.d.ts +3 -0
  4. package/esm/admob.js +22 -0
  5. package/esm/admob.js.map +1 -0
  6. package/esm/api.d.ts +61 -0
  7. package/esm/api.js +232 -0
  8. package/esm/api.js.map +1 -0
  9. package/esm/app-open.d.ts +17 -0
  10. package/esm/app-open.js +83 -0
  11. package/esm/app-open.js.map +1 -0
  12. package/esm/banner.d.ts +33 -0
  13. package/esm/banner.js +143 -0
  14. package/esm/banner.js.map +1 -0
  15. package/esm/generated.d.ts +77 -0
  16. package/esm/generated.js +104 -0
  17. package/esm/generated.js.map +1 -0
  18. package/esm/index.d.ts +31 -0
  19. package/esm/index.js +95 -0
  20. package/esm/index.js.map +1 -0
  21. package/esm/interstitial.d.ts +7 -0
  22. package/esm/interstitial.js +35 -0
  23. package/esm/interstitial.js.map +1 -0
  24. package/esm/native.d.ts +19 -0
  25. package/esm/native.js +134 -0
  26. package/esm/native.js.map +1 -0
  27. package/esm/rewarded-interstitial.d.ts +10 -0
  28. package/esm/rewarded-interstitial.js +35 -0
  29. package/esm/rewarded-interstitial.js.map +1 -0
  30. package/esm/rewarded.d.ts +14 -0
  31. package/esm/rewarded.js +35 -0
  32. package/esm/rewarded.js.map +1 -0
  33. package/esm/shared.d.ts +2 -0
  34. package/esm/shared.js +3 -0
  35. package/esm/shared.js.map +1 -0
  36. package/lib/admob.d.ts +3 -0
  37. package/lib/admob.js +50 -0
  38. package/lib/admob.js.map +1 -0
  39. package/lib/api.d.ts +61 -0
  40. package/lib/api.js +240 -0
  41. package/lib/api.js.map +1 -0
  42. package/lib/app-open.d.ts +17 -0
  43. package/lib/app-open.js +85 -0
  44. package/lib/app-open.js.map +1 -0
  45. package/lib/banner.d.ts +33 -0
  46. package/lib/banner.js +145 -0
  47. package/lib/banner.js.map +1 -0
  48. package/lib/generated.d.ts +77 -0
  49. package/lib/generated.js +110 -0
  50. package/lib/generated.js.map +1 -0
  51. package/lib/index.d.ts +31 -0
  52. package/lib/index.js +120 -0
  53. package/lib/index.js.map +1 -0
  54. package/lib/interstitial.d.ts +7 -0
  55. package/lib/interstitial.js +37 -0
  56. package/lib/interstitial.js.map +1 -0
  57. package/lib/native.d.ts +19 -0
  58. package/lib/native.js +136 -0
  59. package/lib/native.js.map +1 -0
  60. package/lib/rewarded-interstitial.d.ts +10 -0
  61. package/lib/rewarded-interstitial.js +37 -0
  62. package/lib/rewarded-interstitial.js.map +1 -0
  63. package/lib/rewarded.d.ts +14 -0
  64. package/lib/rewarded.js +37 -0
  65. package/lib/rewarded.js.map +1 -0
  66. package/lib/shared.d.ts +2 -0
  67. package/lib/shared.js +19 -0
  68. package/lib/shared.js.map +1 -0
  69. package/package.json +73 -0
  70. package/plugin.xml +333 -0
  71. package/scripts/iosNSAppTransportSecurity.js +29 -0
  72. package/scripts/iosNSAppTransportSecurity.ts +33 -0
  73. package/scripts/tsconfig.json +5 -0
  74. package/scripts/util.js +34 -0
  75. package/scripts/util.ts +44 -0
  76. package/src/android/cordova/AdMob.java +256 -0
  77. package/src/android/cordova/ExecuteContext.java +174 -0
  78. package/src/android/cordova/Generated.java +72 -0
  79. package/src/android/cordova/ads/AdBase.java +54 -0
  80. package/src/android/cordova/ads/AppOpen.java +98 -0
  81. package/src/android/cordova/ads/Banner.java +370 -0
  82. package/src/android/cordova/ads/Interstitial.java +101 -0
  83. package/src/android/cordova/ads/Native.java +162 -0
  84. package/src/android/cordova/ads/Rewarded.java +108 -0
  85. package/src/android/cordova/ads/RewardedInterstitial.java +108 -0
  86. package/src/android/core/Ad.java +73 -0
  87. package/src/android/core/Context.java +186 -0
  88. package/src/android/core/GenericAd.java +22 -0
  89. package/src/android/core/Helper.java +134 -0
  90. package/src/browser/AdMobProxy.js +33 -0
  91. package/src/ios/AMBAdBase.swift +72 -0
  92. package/src/ios/AMBAppOpenAd.swift +87 -0
  93. package/src/ios/AMBBanner.swift +294 -0
  94. package/src/ios/AMBContext.swift +166 -0
  95. package/src/ios/AMBCore.swift +232 -0
  96. package/src/ios/AMBGenerated.swift +45 -0
  97. package/src/ios/AMBInterstitial.swift +69 -0
  98. package/src/ios/AMBNativeAd.swift +128 -0
  99. package/src/ios/AMBPlugin.swift +198 -0
  100. package/src/ios/AMBRewarded.swift +72 -0
  101. package/src/ios/AMBRewardedInterstitial.swift +72 -0
  102. package/src/www/admob.ts +26 -0
  103. package/src/www/api.ts +156 -0
  104. package/src/www/app-open.ts +27 -0
  105. package/src/www/banner.ts +102 -0
  106. package/src/www/cordova.d.ts +9 -0
  107. package/src/www/generated.ts +125 -0
  108. package/src/www/index.ts +88 -0
  109. package/src/www/interstitial.ts +17 -0
  110. package/src/www/native.ts +54 -0
  111. package/src/www/rewarded-interstitial.ts +20 -0
  112. package/src/www/rewarded.ts +26 -0
  113. package/src/www/shared.ts +2 -0
  114. package/www/admob.js +675 -0
@@ -0,0 +1,232 @@
1
+ import Foundation
2
+ import UIKit
3
+ import GoogleMobileAds
4
+
5
+ enum AMBCoreError: Error {
6
+ case notImplemented
7
+ case unknown
8
+ }
9
+
10
+ protocol AMBHelperAdapter {
11
+ }
12
+
13
+ extension AMBHelperAdapter {
14
+ }
15
+
16
+ class AMBHelper {
17
+ static let window = UIApplication.shared.keyWindow!
18
+
19
+ static var topAnchor: NSLayoutYAxisAnchor {
20
+ if #available(iOS 11.0, *) {
21
+ return window.safeAreaLayoutGuide.topAnchor
22
+ } else {
23
+ return window.topAnchor
24
+ }
25
+ }
26
+
27
+ static var bottomAnchor: NSLayoutYAxisAnchor {
28
+ if #available(iOS 11.0, *) {
29
+ return window.safeAreaLayoutGuide.bottomAnchor
30
+ } else {
31
+ return window.bottomAnchor
32
+ }
33
+ }
34
+
35
+ static var frame: CGRect {
36
+ if #available(iOS 11.0, *) {
37
+ return window.frame.inset(by: window.safeAreaInsets)
38
+ } else {
39
+ return window.frame
40
+ }
41
+ }
42
+
43
+ let adapter: AMBHelperAdapter
44
+
45
+ init(_ adapter: AMBHelperAdapter) {
46
+ self.adapter = adapter
47
+ }
48
+ }
49
+
50
+ protocol AMBCoreContext {
51
+ func has(_ name: String) -> Bool
52
+ func optBool(_ name: String) -> Bool?
53
+ func optFloat(_ name: String) -> Float?
54
+ func optInt(_ name: String) -> Int?
55
+ func optString(_ name: String, _ defaultValue: String) -> String
56
+ func optStringArray(_ name: String) -> [String]?
57
+
58
+ func resolve(_ data: [String: Any])
59
+ func resolve(_ data: Bool)
60
+
61
+ func reject(_ msg: String)
62
+ }
63
+
64
+ extension AMBCoreContext {
65
+ func optString(_ name: String) -> String? {
66
+ if has(name) {
67
+ return optString(name, "")
68
+ }
69
+ return nil
70
+ }
71
+
72
+ func optAppMuted() -> Bool? {
73
+ return optBool("appMuted")
74
+ }
75
+
76
+ func optAppVolume() -> Float? {
77
+ return optFloat("appVolume")
78
+ }
79
+
80
+ func optId() -> Int? {
81
+ return optInt("id")
82
+ }
83
+
84
+ func optPosition() -> String {
85
+ return optString("position", "bottom")
86
+ }
87
+
88
+ func optAdUnitID() -> String? {
89
+ return optString("adUnitId")
90
+ }
91
+
92
+ func optAd() -> AMBCoreAd? {
93
+ guard let id = optId(),
94
+ let ad = AMBCoreAd.ads[id]
95
+ else {
96
+ return nil
97
+ }
98
+ return ad
99
+ }
100
+
101
+ func optAdOrError() -> AMBCoreAd? {
102
+ if let ad = optAd() {
103
+ return ad
104
+ } else {
105
+ reject("Ad not found: \(optId() ?? -1)")
106
+ return nil
107
+ }
108
+ }
109
+
110
+ func optMaxAdContentRating() -> GADMaxAdContentRating? {
111
+ switch optString("maxAdContentRating") {
112
+ case "G":
113
+ return GADMaxAdContentRating.general
114
+ case "MA":
115
+ return GADMaxAdContentRating.matureAudience
116
+ case "PG":
117
+ return GADMaxAdContentRating.parentalGuidance
118
+ case "T":
119
+ return GADMaxAdContentRating.teen
120
+ default:
121
+ return nil
122
+ }
123
+ }
124
+
125
+ func optChildDirectedTreatmentTag() -> Bool? {
126
+ return optBool("tagForChildDirectedTreatment")
127
+ }
128
+
129
+ func optUnderAgeOfConsentTag() -> Bool? {
130
+ return optBool("tagForUnderAgeOfConsent")
131
+ }
132
+
133
+ func optTestDeviceIds() -> [String]? {
134
+ return optStringArray("testDeviceIds")
135
+ }
136
+
137
+ func optGADRequest() -> GADRequest {
138
+ let request = GADRequest()
139
+ if let contentURL = optString("contentUrl") {
140
+ request.contentURL = contentURL
141
+ }
142
+ if let keywords = optStringArray("keywords") {
143
+ request.keywords = keywords
144
+ }
145
+ let extras = GADExtras()
146
+ if let npa = optString("npa") {
147
+ extras.additionalParameters = ["npa": npa]
148
+ }
149
+ request.register(extras)
150
+ return request
151
+ }
152
+
153
+ func resolve() {
154
+ resolve([:])
155
+ }
156
+
157
+ func resolve(_ data: Bool) {
158
+ resolve(["value": data])
159
+ }
160
+
161
+ func reject() {
162
+ return reject(AMBCoreError.unknown)
163
+ }
164
+
165
+ func reject(_ error: Error) {
166
+ reject(error.localizedDescription)
167
+ }
168
+
169
+ func configure() {
170
+ if let muted = optAppMuted() {
171
+ GADMobileAds.sharedInstance().applicationMuted = muted
172
+ }
173
+ if let volume = optAppVolume() {
174
+ GADMobileAds.sharedInstance().applicationVolume = volume
175
+ }
176
+
177
+ let requestConfiguration = GADMobileAds.sharedInstance().requestConfiguration
178
+ if let maxAdContentRating = optMaxAdContentRating() {
179
+ requestConfiguration.maxAdContentRating = maxAdContentRating
180
+ }
181
+ if let tag = optChildDirectedTreatmentTag() {
182
+ requestConfiguration.tag(forChildDirectedTreatment: tag)
183
+ }
184
+ if let tag = optUnderAgeOfConsentTag() {
185
+ requestConfiguration.tagForUnderAge(ofConsent: tag)
186
+ }
187
+ if let testDevices = optTestDeviceIds() {
188
+ requestConfiguration.testDeviceIdentifiers = testDevices
189
+ }
190
+ if let sameAppKey = optBool("sameAppKey") {
191
+ requestConfiguration.setSameAppKeyEnabled(sameAppKey)
192
+ }
193
+
194
+ resolve()
195
+ }
196
+ }
197
+
198
+ class AMBCoreAd: NSObject {
199
+ static var ads = [Int: AMBCoreAd]()
200
+
201
+ let id: Int
202
+ let adUnitId: String
203
+ let adRequest: GADRequest
204
+
205
+ init(id: Int, adUnitId: String, adRequest: GADRequest) {
206
+ self.id = id
207
+ self.adUnitId = adUnitId
208
+ self.adRequest = adRequest
209
+
210
+ super.init()
211
+
212
+ AMBCoreAd.ads[id] = self
213
+ }
214
+
215
+ convenience init?(_ ctx: AMBCoreContext) {
216
+ guard let id = ctx.optId(),
217
+ let adUnitId = ctx.optAdUnitID()
218
+ else {
219
+ return nil
220
+ }
221
+ self.init(id: id, adUnitId: adUnitId, adRequest: ctx.optGADRequest())
222
+ }
223
+
224
+ deinit {
225
+ let key = self.id
226
+ DispatchQueue.main.async {
227
+ AMBCoreAd.ads.removeValue(forKey: key)
228
+ }
229
+ }
230
+ }
231
+
232
+ class AMBBannerPlaceholder: UIView {}
@@ -0,0 +1,45 @@
1
+ // THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2
+ struct AMBBannerPosition {
3
+ static let bottom = "bottom"
4
+ static let top = "top"
5
+ }
6
+
7
+ struct AMBEvents {
8
+ static let adClick = "admob.ad.click"
9
+ static let adDismiss = "admob.ad.dismiss"
10
+ static let adImpression = "admob.ad.impression"
11
+ static let adLoad = "admob.ad.load"
12
+ static let adLoadFail = "admob.ad.loadfail"
13
+ static let adReward = "admob.ad.reward"
14
+ static let adShow = "admob.ad.show"
15
+ static let adShowFail = "admob.ad.showfail"
16
+ static let bannerClick = "admob.banner.click"
17
+ static let bannerClose = "admob.banner.close"
18
+ static let bannerImpression = "admob.banner.impression"
19
+ static let bannerLoad = "admob.banner.load"
20
+ static let bannerLoadFail = "admob.banner.loadfail"
21
+ static let bannerOpen = "admob.banner.open"
22
+ static let bannerSize = "admob.banner.size"
23
+ static let bannerSizeChange = "admob.banner.sizechange"
24
+ static let interstitialDismiss = "admob.interstitial.dismiss"
25
+ static let interstitialImpression = "admob.interstitial.impression"
26
+ static let interstitialLoad = "admob.interstitial.load"
27
+ static let interstitialLoadFail = "admob.interstitial.loadfail"
28
+ static let interstitialShow = "admob.interstitial.show"
29
+ static let interstitialShowFail = "admob.interstitial.showfail"
30
+ static let ready = "admob.ready"
31
+ static let rewardedDismiss = "admob.rewarded.dismiss"
32
+ static let rewardedImpression = "admob.rewarded.impression"
33
+ static let rewardedInterstitialDismiss = "admob.rewardedi.dismiss"
34
+ static let rewardedInterstitialImpression = "admob.rewardedi.impression"
35
+ static let rewardedInterstitialLoad = "admob.rewardedi.load"
36
+ static let rewardedInterstitialLoadFail = "admob.rewardedi.loadfail"
37
+ static let rewardedInterstitialReward = "admob.rewardedi.reward"
38
+ static let rewardedInterstitialShow = "admob.rewardedi.show"
39
+ static let rewardedInterstitialShowFail = "admob.rewardedi.showfail"
40
+ static let rewardedLoad = "admob.rewarded.load"
41
+ static let rewardedLoadFail = "admob.rewarded.loadfail"
42
+ static let rewardedReward = "admob.rewarded.reward"
43
+ static let rewardedShow = "admob.rewarded.show"
44
+ static let rewardedShowFail = "admob.rewarded.showfail"
45
+ }
@@ -0,0 +1,69 @@
1
+ import GoogleMobileAds
2
+
3
+ class AMBInterstitial: AMBAdBase, GADFullScreenContentDelegate {
4
+ var mAd: GADInterstitialAd?
5
+
6
+ deinit {
7
+ clear()
8
+ }
9
+
10
+ override func isLoaded() -> Bool {
11
+ return self.mAd != nil
12
+ }
13
+
14
+ override func load(_ ctx: AMBContext) {
15
+ clear()
16
+
17
+ GADInterstitialAd.load(
18
+ withAdUnitID: adUnitId,
19
+ request: adRequest,
20
+ completionHandler: { ad, error in
21
+ if error != nil {
22
+ self.emit(AMBEvents.adLoadFail, error!)
23
+ self.emit(AMBEvents.interstitialLoadFail, error!)
24
+ ctx.reject(error!)
25
+ return
26
+ }
27
+
28
+ self.mAd = ad
29
+ ad?.fullScreenContentDelegate = self
30
+
31
+ self.emit(AMBEvents.adLoad)
32
+ self.emit(AMBEvents.interstitialLoad)
33
+
34
+ ctx.resolve()
35
+ })
36
+ }
37
+
38
+ override func show(_ ctx: AMBContext) {
39
+ mAd?.present(fromRootViewController: plugin.viewController)
40
+ ctx.resolve()
41
+ }
42
+
43
+ func adDidRecordImpression(_ ad: GADFullScreenPresentingAd) {
44
+ self.emit(AMBEvents.adImpression)
45
+ self.emit(AMBEvents.interstitialImpression)
46
+ }
47
+
48
+ func ad(_ ad: GADFullScreenPresentingAd, didFailToPresentFullScreenContentWithError error: Error) {
49
+ clear()
50
+ self.emit(AMBEvents.adShowFail, error)
51
+ self.emit(AMBEvents.interstitialShowFail, error)
52
+ }
53
+
54
+ func adWillPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) {
55
+ self.emit(AMBEvents.adShow)
56
+ self.emit(AMBEvents.interstitialShow)
57
+ }
58
+
59
+ func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) {
60
+ clear()
61
+ self.emit(AMBEvents.adDismiss)
62
+ self.emit(AMBEvents.interstitialDismiss)
63
+ }
64
+
65
+ private func clear() {
66
+ mAd?.fullScreenContentDelegate = nil
67
+ mAd = nil
68
+ }
69
+ }
@@ -0,0 +1,128 @@
1
+ import Foundation
2
+ import GoogleMobileAds
3
+
4
+ protocol AMBNativeAdViewProvider: NSObjectProtocol {
5
+ func createView(_ nativeAd: GADNativeAd) -> UIView
6
+ // delegate
7
+ func didShow(_ ad: AMBNativeAd)
8
+ func didHide(_ ad: AMBNativeAd)
9
+ }
10
+
11
+ extension AMBNativeAdViewProvider {
12
+ func didShow(_ ad: AMBNativeAd) {}
13
+ func didHide(_ ad: AMBNativeAd) {}
14
+ }
15
+
16
+ class AMBNativeAd: AMBAdBase, GADNativeAdLoaderDelegate, GADNativeAdDelegate {
17
+ static var providers = [String: AMBNativeAdViewProvider]()
18
+
19
+ var mLoader: GADAdLoader!
20
+ let viewProvider: AMBNativeAdViewProvider
21
+ var mAd: GADNativeAd?
22
+ var ctxLoad: AMBContext?
23
+
24
+ lazy var view: UIView = {
25
+ return viewProvider.createView(mAd!)
26
+ }()
27
+
28
+ init(id: Int, adUnitId: String, adRequest: GADRequest, viewProvider: AMBNativeAdViewProvider) {
29
+ self.viewProvider = viewProvider
30
+
31
+ super.init(id: id, adUnitId: adUnitId, adRequest: adRequest)
32
+
33
+ mLoader = GADAdLoader(adUnitID: adUnitId, rootViewController: plugin.viewController,
34
+ adTypes: [.native], options: nil)
35
+ mLoader.delegate = self
36
+ }
37
+
38
+ convenience init?(_ ctx: AMBContext) {
39
+ let view = ctx.optString("view") ?? "default"
40
+ guard let id = ctx.optId(),
41
+ let adUnitId = ctx.optAdUnitID(),
42
+ let viewProvider = Self.providers[view]
43
+ else {
44
+ return nil
45
+ }
46
+ self.init(id: id,
47
+ adUnitId: adUnitId,
48
+ adRequest: ctx.optGADRequest(),
49
+ viewProvider: viewProvider)
50
+ }
51
+
52
+ override func load(_ ctx: AMBContext) {
53
+ ctxLoad = ctx
54
+ mLoader.load(adRequest)
55
+ }
56
+
57
+ override func isLoaded() -> Bool {
58
+ if mLoader == nil {
59
+ return false
60
+ }
61
+ return !mLoader.isLoading
62
+ }
63
+
64
+ override func show(_ ctx: AMBContext) {
65
+ if let x = ctx.opt("x") as? Double,
66
+ let y = ctx.opt("y") as? Double,
67
+ let w = ctx.opt("width") as? Double,
68
+ let h = ctx.opt("height") as? Double {
69
+ view.frame = CGRect(x: x, y: y, width: w, height: h)
70
+ }
71
+
72
+ if let rootView = plugin.viewController.view, view.superview != rootView {
73
+ rootView.addSubview(view)
74
+ }
75
+ view.isHidden = false
76
+
77
+ viewProvider.didShow(self)
78
+ }
79
+
80
+ override func hide(_ ctx: AMBContext) {
81
+ view.isHidden = true
82
+ viewProvider.didHide(self)
83
+ ctx.resolve()
84
+ }
85
+
86
+ func adLoader(_ adLoader: GADAdLoader, didReceive nativeAd: GADNativeAd) {
87
+ mAd = nativeAd
88
+ nativeAd.delegate = self
89
+ self.emit(AMBEvents.adLoad)
90
+ if !adLoader.isLoading {
91
+ ctxLoad?.resolve()
92
+ ctxLoad = nil
93
+ }
94
+ }
95
+
96
+ func adLoader(_ adLoader: GADAdLoader, didFailToReceiveAdWithError error: Error) {
97
+ self.emit(AMBEvents.adLoadFail, error)
98
+ if !adLoader.isLoading {
99
+ ctxLoad?.reject(error)
100
+ ctxLoad = nil
101
+ }
102
+ }
103
+
104
+ func nativeAdDidRecordImpression(_ nativeAd: GADNativeAd) {
105
+ self.emit(AMBEvents.adImpression, nativeAd)
106
+ }
107
+
108
+ func nativeAdDidRecordClick(_ nativeAd: GADNativeAd) {
109
+ self.emit(AMBEvents.adClick, nativeAd)
110
+ }
111
+
112
+ func nativeAdWillPresentScreen(_ nativeAd: GADNativeAd) {
113
+ self.emit(AMBEvents.adShow, nativeAd)
114
+ }
115
+
116
+ func nativeAdWillDismissScreen(_ nativeAd: GADNativeAd) {
117
+ // The native ad will dismiss a full screen view.
118
+ }
119
+
120
+ func nativeAdDidDismissScreen(_ nativeAd: GADNativeAd) {
121
+ self.emit(AMBEvents.adDismiss, nativeAd)
122
+ }
123
+
124
+ func nativeAdWillLeaveApplication(_ nativeAd: GADNativeAd) {
125
+ // The native ad will cause the application to become inactive and
126
+ // open a new application.
127
+ }
128
+ }
@@ -0,0 +1,198 @@
1
+ #if canImport(AppTrackingTransparency)
2
+ import AppTrackingTransparency
3
+ #endif
4
+ import GoogleMobileAds
5
+
6
+ @objc(AMBPlugin)
7
+ class AMBPlugin: CDVPlugin {
8
+ static func registerNativeAdViewProviders(_ providers: [String: AMBNativeAdViewProvider]) {
9
+ AMBNativeAd.providers.merge(providers) {(_, new) in new}
10
+ }
11
+
12
+ var readyCallbackId: String!
13
+
14
+ deinit {
15
+ readyCallbackId = nil
16
+ }
17
+
18
+ override func pluginInitialize() {
19
+ super.pluginInitialize()
20
+
21
+ AMBContext.plugin = self
22
+
23
+ if let x = self.commandDelegate.settings["disableSDKCrashReporting".lowercased()] as? String,
24
+ x == "true" {
25
+ GADMobileAds.sharedInstance().disableSDKCrashReporting()
26
+ }
27
+ }
28
+
29
+ @objc func ready(_ command: CDVInvokedUrlCommand) {
30
+ readyCallbackId = command.callbackId
31
+
32
+ DispatchQueue.global(qos: .background).async {
33
+ self.emit(AMBEvents.ready, data: ["isRunningInTestLab": false])
34
+ }
35
+ }
36
+
37
+ @objc func configure(_ command: CDVInvokedUrlCommand) {
38
+ let ctx = AMBContext(command)
39
+ ctx.configure()
40
+ }
41
+
42
+ @objc func configRequest(_ command: CDVInvokedUrlCommand) {
43
+ let ctx = AMBContext(command)
44
+ let requestConfiguration = GADMobileAds.sharedInstance().requestConfiguration
45
+
46
+ if let maxAdContentRating = ctx.optMaxAdContentRating() {
47
+ requestConfiguration.maxAdContentRating = maxAdContentRating
48
+ }
49
+
50
+ if let tag = ctx.optChildDirectedTreatmentTag() {
51
+ requestConfiguration.tag(forChildDirectedTreatment: tag)
52
+ }
53
+
54
+ if let tag = ctx.optUnderAgeOfConsentTag() {
55
+ requestConfiguration.tagForUnderAge(ofConsent: tag)
56
+ }
57
+
58
+ if let testDevices = ctx.optTestDeviceIds() {
59
+ requestConfiguration.testDeviceIdentifiers = testDevices
60
+ }
61
+
62
+ ctx.resolve()
63
+ }
64
+
65
+ @objc func requestTrackingAuthorization(_ command: CDVInvokedUrlCommand) {
66
+ let ctx = AMBContext(command)
67
+
68
+ if #available(iOS 14, *) {
69
+ ATTrackingManager.requestTrackingAuthorization(completionHandler: { status in
70
+ ctx.resolve(status.rawValue)
71
+ })
72
+ } else {
73
+ ctx.resolve(false)
74
+ }
75
+ }
76
+
77
+ @objc func start(_ command: CDVInvokedUrlCommand) {
78
+ let ctx = AMBContext(command)
79
+
80
+ GADMobileAds.sharedInstance().start(completionHandler: { _ in
81
+ ctx.resolve(["version": GADMobileAds.sharedInstance().sdkVersion])
82
+ })
83
+ }
84
+
85
+ @objc func setAppMuted(_ command: CDVInvokedUrlCommand) {
86
+ let ctx = AMBContext(command)
87
+
88
+ if let muted = ctx.opt0() as? Bool {
89
+ GADMobileAds.sharedInstance().applicationMuted = muted
90
+ ctx.resolve()
91
+ } else {
92
+ ctx.reject()
93
+ }
94
+ }
95
+
96
+ @objc func setAppVolume(_ command: CDVInvokedUrlCommand) {
97
+ let ctx = AMBContext(command)
98
+
99
+ if let volume = ctx.opt0() as? Float {
100
+ GADMobileAds.sharedInstance().applicationVolume = volume
101
+ ctx.resolve()
102
+ } else {
103
+ ctx.reject()
104
+ }
105
+ }
106
+
107
+ @objc func adCreate(_ command: CDVInvokedUrlCommand) {
108
+ let ctx = AMBContext(command)
109
+
110
+ DispatchQueue.main.async {
111
+ if let adClass = ctx.optString("cls") {
112
+ var ad: AMBCoreAd?
113
+ switch adClass {
114
+ case "AppOpenAd":
115
+ ad = AMBAppOpenAd(ctx)
116
+ case "BannerAd":
117
+ ad = AMBBanner(ctx)
118
+ case "InterstitialAd":
119
+ ad = AMBInterstitial(ctx)
120
+ case "NativeAd":
121
+ ad = AMBNativeAd(ctx)
122
+ case "RewardedAd":
123
+ ad = AMBRewarded(ctx)
124
+ case "RewardedInterstitialAd":
125
+ ad = AMBRewardedInterstitial(ctx)
126
+ default:
127
+ break
128
+ }
129
+ if ad != nil {
130
+ ctx.resolve()
131
+ } else {
132
+ ctx.reject("fail to create ad: \(ctx.optId() ?? -1)")
133
+ }
134
+ } else {
135
+ ctx.reject()
136
+ }
137
+ }
138
+ }
139
+
140
+ @objc func adIsLoaded(_ command: CDVInvokedUrlCommand) {
141
+ let ctx = AMBContext(command)
142
+
143
+ DispatchQueue.main.async {
144
+ if let ad = ctx.optAdOrError() as? AMBAdBase {
145
+ ctx.resolve(ad.isLoaded())
146
+ }
147
+ }
148
+ }
149
+
150
+ @objc func adLoad(_ command: CDVInvokedUrlCommand) {
151
+ let ctx = AMBContext(command)
152
+
153
+ DispatchQueue.main.async {
154
+ if let ad = ctx.optAdOrError() as? AMBAdBase {
155
+ ad.load(ctx)
156
+ }
157
+ }
158
+ }
159
+
160
+ @objc func adShow(_ command: CDVInvokedUrlCommand) {
161
+ let ctx = AMBContext(command)
162
+
163
+ DispatchQueue.main.async {
164
+ if let ad = ctx.optAdOrError() as? AMBAdBase {
165
+ if ad.isLoaded() {
166
+ ad.show(ctx)
167
+ ctx.resolve(true)
168
+ } else {
169
+ ctx.resolve(false)
170
+ }
171
+ }
172
+ }
173
+ }
174
+
175
+ @objc func adHide(_ command: CDVInvokedUrlCommand) {
176
+ let ctx = AMBContext(command)
177
+
178
+ DispatchQueue.main.async {
179
+ if let ad = ctx.optAdOrError() as? AMBAdBase {
180
+ ad.hide(ctx)
181
+ }
182
+ }
183
+ }
184
+
185
+ @objc func bannerConfig(_ command: CDVInvokedUrlCommand) {
186
+ let ctx = AMBContext(command)
187
+
188
+ DispatchQueue.main.async {
189
+ AMBBanner.config(ctx)
190
+ }
191
+ }
192
+
193
+ func emit(_ eventName: String, data: Any = NSNull()) {
194
+ let result = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: ["type": eventName, "data": data])
195
+ result?.setKeepCallbackAs(true)
196
+ self.commandDelegate.send(result, callbackId: readyCallbackId)
197
+ }
198
+ }