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.
- package/CHANGELOG.md +0 -0
- package/README.md +17 -0
- package/esm/admob.d.ts +3 -0
- package/esm/admob.js +22 -0
- package/esm/admob.js.map +1 -0
- package/esm/api.d.ts +61 -0
- package/esm/api.js +232 -0
- package/esm/api.js.map +1 -0
- package/esm/app-open.d.ts +17 -0
- package/esm/app-open.js +83 -0
- package/esm/app-open.js.map +1 -0
- package/esm/banner.d.ts +33 -0
- package/esm/banner.js +143 -0
- package/esm/banner.js.map +1 -0
- package/esm/generated.d.ts +77 -0
- package/esm/generated.js +104 -0
- package/esm/generated.js.map +1 -0
- package/esm/index.d.ts +31 -0
- package/esm/index.js +95 -0
- package/esm/index.js.map +1 -0
- package/esm/interstitial.d.ts +7 -0
- package/esm/interstitial.js +35 -0
- package/esm/interstitial.js.map +1 -0
- package/esm/native.d.ts +19 -0
- package/esm/native.js +134 -0
- package/esm/native.js.map +1 -0
- package/esm/rewarded-interstitial.d.ts +10 -0
- package/esm/rewarded-interstitial.js +35 -0
- package/esm/rewarded-interstitial.js.map +1 -0
- package/esm/rewarded.d.ts +14 -0
- package/esm/rewarded.js +35 -0
- package/esm/rewarded.js.map +1 -0
- package/esm/shared.d.ts +2 -0
- package/esm/shared.js +3 -0
- package/esm/shared.js.map +1 -0
- package/lib/admob.d.ts +3 -0
- package/lib/admob.js +50 -0
- package/lib/admob.js.map +1 -0
- package/lib/api.d.ts +61 -0
- package/lib/api.js +240 -0
- package/lib/api.js.map +1 -0
- package/lib/app-open.d.ts +17 -0
- package/lib/app-open.js +85 -0
- package/lib/app-open.js.map +1 -0
- package/lib/banner.d.ts +33 -0
- package/lib/banner.js +145 -0
- package/lib/banner.js.map +1 -0
- package/lib/generated.d.ts +77 -0
- package/lib/generated.js +110 -0
- package/lib/generated.js.map +1 -0
- package/lib/index.d.ts +31 -0
- package/lib/index.js +120 -0
- package/lib/index.js.map +1 -0
- package/lib/interstitial.d.ts +7 -0
- package/lib/interstitial.js +37 -0
- package/lib/interstitial.js.map +1 -0
- package/lib/native.d.ts +19 -0
- package/lib/native.js +136 -0
- package/lib/native.js.map +1 -0
- package/lib/rewarded-interstitial.d.ts +10 -0
- package/lib/rewarded-interstitial.js +37 -0
- package/lib/rewarded-interstitial.js.map +1 -0
- package/lib/rewarded.d.ts +14 -0
- package/lib/rewarded.js +37 -0
- package/lib/rewarded.js.map +1 -0
- package/lib/shared.d.ts +2 -0
- package/lib/shared.js +19 -0
- package/lib/shared.js.map +1 -0
- package/package.json +73 -0
- package/plugin.xml +333 -0
- package/scripts/iosNSAppTransportSecurity.js +29 -0
- package/scripts/iosNSAppTransportSecurity.ts +33 -0
- package/scripts/tsconfig.json +5 -0
- package/scripts/util.js +34 -0
- package/scripts/util.ts +44 -0
- package/src/android/cordova/AdMob.java +256 -0
- package/src/android/cordova/ExecuteContext.java +174 -0
- package/src/android/cordova/Generated.java +72 -0
- package/src/android/cordova/ads/AdBase.java +54 -0
- package/src/android/cordova/ads/AppOpen.java +98 -0
- package/src/android/cordova/ads/Banner.java +370 -0
- package/src/android/cordova/ads/Interstitial.java +101 -0
- package/src/android/cordova/ads/Native.java +162 -0
- package/src/android/cordova/ads/Rewarded.java +108 -0
- package/src/android/cordova/ads/RewardedInterstitial.java +108 -0
- package/src/android/core/Ad.java +73 -0
- package/src/android/core/Context.java +186 -0
- package/src/android/core/GenericAd.java +22 -0
- package/src/android/core/Helper.java +134 -0
- package/src/browser/AdMobProxy.js +33 -0
- package/src/ios/AMBAdBase.swift +72 -0
- package/src/ios/AMBAppOpenAd.swift +87 -0
- package/src/ios/AMBBanner.swift +294 -0
- package/src/ios/AMBContext.swift +166 -0
- package/src/ios/AMBCore.swift +232 -0
- package/src/ios/AMBGenerated.swift +45 -0
- package/src/ios/AMBInterstitial.swift +69 -0
- package/src/ios/AMBNativeAd.swift +128 -0
- package/src/ios/AMBPlugin.swift +198 -0
- package/src/ios/AMBRewarded.swift +72 -0
- package/src/ios/AMBRewardedInterstitial.swift +72 -0
- package/src/www/admob.ts +26 -0
- package/src/www/api.ts +156 -0
- package/src/www/app-open.ts +27 -0
- package/src/www/banner.ts +102 -0
- package/src/www/cordova.d.ts +9 -0
- package/src/www/generated.ts +125 -0
- package/src/www/index.ts +88 -0
- package/src/www/interstitial.ts +17 -0
- package/src/www/native.ts +54 -0
- package/src/www/rewarded-interstitial.ts +20 -0
- package/src/www/rewarded.ts +26 -0
- package/src/www/shared.ts +2 -0
- package/www/admob.js +675 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import GoogleMobileAds
|
|
2
|
+
|
|
3
|
+
class AMBAdBase: AMBCoreAd {
|
|
4
|
+
func isLoaded() -> Bool {
|
|
5
|
+
#if targetEnvironment(simulator)
|
|
6
|
+
fatalError(AMBCoreError.notImplemented.localizedDescription)
|
|
7
|
+
#else
|
|
8
|
+
return false
|
|
9
|
+
#endif
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
func load(_ ctx: AMBContext) {
|
|
13
|
+
ctx.reject(AMBCoreError.notImplemented)
|
|
14
|
+
#if targetEnvironment(simulator)
|
|
15
|
+
fatalError(AMBCoreError.notImplemented.localizedDescription)
|
|
16
|
+
#endif
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
func show(_ ctx: AMBContext) {
|
|
20
|
+
ctx.reject(AMBCoreError.notImplemented)
|
|
21
|
+
#if targetEnvironment(simulator)
|
|
22
|
+
fatalError(AMBCoreError.notImplemented.localizedDescription)
|
|
23
|
+
#endif
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
func hide(_ ctx: AMBContext) {
|
|
27
|
+
ctx.reject(AMBCoreError.notImplemented)
|
|
28
|
+
#if targetEnvironment(simulator)
|
|
29
|
+
fatalError(AMBCoreError.notImplemented.localizedDescription)
|
|
30
|
+
#endif
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
var plugin: AMBPlugin {
|
|
34
|
+
return AMBContext.plugin
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
func emit(_ eventName: String) {
|
|
38
|
+
self.emit(eventName, ["adId": self.id])
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
func emit(_ eventName: String, _ error: Error) {
|
|
42
|
+
self.emit(eventName, ["message": error.localizedDescription])
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
func emit(_ eventName: String, _ reward: GADAdReward) {
|
|
46
|
+
self.emit(eventName, [
|
|
47
|
+
"reward": [
|
|
48
|
+
"amount": reward.amount,
|
|
49
|
+
"type": reward.type
|
|
50
|
+
]
|
|
51
|
+
])
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
func emit(_ eventName: String, _ adSize: GADAdSize) {
|
|
55
|
+
self.emit(eventName, [
|
|
56
|
+
"size": [
|
|
57
|
+
"width": adSize.size.width,
|
|
58
|
+
"height": adSize.size.height
|
|
59
|
+
]
|
|
60
|
+
])
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
func emit(_ eventName: String, _ data: [String: Any]) {
|
|
64
|
+
var d: [String: Any] = ["adId": self.id]
|
|
65
|
+
d.merge(data) { (current, _) in current }
|
|
66
|
+
plugin.emit(eventName, data: d)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
func emit(_ eventName: String, _ nativeAd: GADNativeAd) {
|
|
70
|
+
plugin.emit(eventName, data: ["adId": nativeAd.hashValue])
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import GoogleMobileAds
|
|
3
|
+
|
|
4
|
+
class AMBAppOpenAd: AMBAdBase, GADFullScreenContentDelegate {
|
|
5
|
+
|
|
6
|
+
let orientation: UIInterfaceOrientation
|
|
7
|
+
|
|
8
|
+
var mAd: GADAppOpenAd?
|
|
9
|
+
|
|
10
|
+
init(id: Int, adUnitId: String, adRequest: GADRequest, orientation: UIInterfaceOrientation) {
|
|
11
|
+
self.orientation = orientation
|
|
12
|
+
|
|
13
|
+
super.init(id: id, adUnitId: adUnitId, adRequest: adRequest)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
convenience init?(_ ctx: AMBContext) {
|
|
17
|
+
guard let id = ctx.optId(),
|
|
18
|
+
let adUnitId = ctx.optAdUnitID()
|
|
19
|
+
else {
|
|
20
|
+
return nil
|
|
21
|
+
}
|
|
22
|
+
var orientation = UIInterfaceOrientation.portrait
|
|
23
|
+
if let v = ctx.opts?.value(forKey: "orientation") as? Int {
|
|
24
|
+
orientation = UIInterfaceOrientation(rawValue: v)!
|
|
25
|
+
}
|
|
26
|
+
self.init(id: id,
|
|
27
|
+
adUnitId: adUnitId,
|
|
28
|
+
adRequest: ctx.optGADRequest(),
|
|
29
|
+
orientation: orientation)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
deinit {
|
|
33
|
+
clear()
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
override func isLoaded() -> Bool {
|
|
37
|
+
return mAd != nil
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
override func load(_ ctx: AMBContext) {
|
|
41
|
+
clear()
|
|
42
|
+
|
|
43
|
+
GADAppOpenAd.load(
|
|
44
|
+
withAdUnitID: self.adUnitId,
|
|
45
|
+
request: adRequest,
|
|
46
|
+
orientation: self.orientation,
|
|
47
|
+
completionHandler: { (ad, error) in
|
|
48
|
+
if error != nil {
|
|
49
|
+
self.emit(AMBEvents.adLoadFail, error!)
|
|
50
|
+
ctx.reject(error!)
|
|
51
|
+
return
|
|
52
|
+
}
|
|
53
|
+
ad?.fullScreenContentDelegate = self
|
|
54
|
+
self.mAd = ad
|
|
55
|
+
|
|
56
|
+
self.emit(AMBEvents.adLoad)
|
|
57
|
+
ctx.resolve()
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
override func show(_ ctx: AMBContext) {
|
|
62
|
+
mAd?.present(fromRootViewController: AMBContext.plugin.viewController)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
func adDidRecordImpression(_ ad: GADFullScreenPresentingAd) {
|
|
66
|
+
self.emit(AMBEvents.adImpression)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
func ad(_ ad: GADFullScreenPresentingAd, didFailToPresentFullScreenContentWithError error: Error) {
|
|
70
|
+
clear()
|
|
71
|
+
self.emit(AMBEvents.adShowFail, error)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
func adWillPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) {
|
|
75
|
+
self.emit(AMBEvents.adShow)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) {
|
|
79
|
+
clear()
|
|
80
|
+
self.emit(AMBEvents.adDismiss)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
private func clear() {
|
|
84
|
+
mAd?.fullScreenContentDelegate = nil
|
|
85
|
+
mAd = nil
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import GoogleMobileAds
|
|
2
|
+
import UIKit
|
|
3
|
+
|
|
4
|
+
class AMBBannerStackView: UIStackView {
|
|
5
|
+
static let shared = AMBBannerStackView(frame: AMBHelper.window.frame)
|
|
6
|
+
|
|
7
|
+
static let topConstraint = shared.topAnchor.constraint(equalTo: AMBHelper.topAnchor, constant: 0)
|
|
8
|
+
static let bottomConstraint = shared.bottomAnchor.constraint(equalTo: AMBHelper.bottomAnchor, constant: 0)
|
|
9
|
+
|
|
10
|
+
lazy var contentView: UIView = {
|
|
11
|
+
let v = UIView(frame: self.frame)
|
|
12
|
+
v.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
|
13
|
+
v.isUserInteractionEnabled = false
|
|
14
|
+
return v
|
|
15
|
+
}()
|
|
16
|
+
|
|
17
|
+
var hasTopBanner: Bool {
|
|
18
|
+
return self.arrangedSubviews.first is AMBBannerPlaceholder
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
var hasBottomBanner: Bool {
|
|
22
|
+
return self.arrangedSubviews.last is AMBBannerPlaceholder
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
func prepare() {
|
|
26
|
+
if !self.arrangedSubviews.isEmpty {
|
|
27
|
+
return
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
self.isUserInteractionEnabled = false
|
|
31
|
+
self.axis = .vertical
|
|
32
|
+
self.distribution = .fill
|
|
33
|
+
self.alignment = .fill
|
|
34
|
+
self.translatesAutoresizingMaskIntoConstraints = false
|
|
35
|
+
|
|
36
|
+
self.addArrangedSubview(contentView)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
class AMBBanner: AMBAdBase, GADBannerViewDelegate, GADAdSizeDelegate {
|
|
41
|
+
static let stackView = AMBBannerStackView.shared
|
|
42
|
+
|
|
43
|
+
static let priortyLeast = UILayoutPriority(10)
|
|
44
|
+
|
|
45
|
+
static var rootObservation: NSKeyValueObservation?
|
|
46
|
+
static var marginTop: CGFloat?
|
|
47
|
+
|
|
48
|
+
static var rootView: UIView {
|
|
49
|
+
return AMBContext.plugin.viewController.view!
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
static var mainView: UIView {
|
|
53
|
+
return AMBContext.plugin.webView
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
static var statusBarBackgroundView: UIView? {
|
|
57
|
+
let statusBarFrame = UIApplication.shared.statusBarFrame
|
|
58
|
+
return rootView.subviews.first(where: { $0.frame.equalTo(statusBarFrame) })
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
static func config(_ ctx: AMBContext) {
|
|
62
|
+
if let bgColor = ctx.optBackgroundColor() {
|
|
63
|
+
Self.rootView.backgroundColor = bgColor
|
|
64
|
+
}
|
|
65
|
+
Self.marginTop = ctx.optMarginTop()
|
|
66
|
+
if Self.marginTop != nil {
|
|
67
|
+
AMBBannerStackView.topConstraint.constant = Self.marginTop!
|
|
68
|
+
}
|
|
69
|
+
if let marginBottom = ctx.optMarginBottom() {
|
|
70
|
+
AMBBannerStackView.bottomConstraint.constant = marginBottom * -1
|
|
71
|
+
}
|
|
72
|
+
ctx.resolve()
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
private static func prepareStackView() {
|
|
76
|
+
if stackView.arrangedSubviews.isEmpty {
|
|
77
|
+
var constraints: [NSLayoutConstraint] = []
|
|
78
|
+
|
|
79
|
+
stackView.prepare()
|
|
80
|
+
rootView.insertSubview(stackView, belowSubview: mainView)
|
|
81
|
+
constraints += [
|
|
82
|
+
stackView.leadingAnchor.constraint(equalTo: rootView.leadingAnchor),
|
|
83
|
+
stackView.trailingAnchor.constraint(equalTo: rootView.trailingAnchor)
|
|
84
|
+
]
|
|
85
|
+
|
|
86
|
+
mainView.translatesAutoresizingMaskIntoConstraints = false
|
|
87
|
+
let placeholderView = stackView.contentView
|
|
88
|
+
constraints += [
|
|
89
|
+
mainView.leadingAnchor.constraint(equalTo: placeholderView.leadingAnchor),
|
|
90
|
+
mainView.trailingAnchor.constraint(equalTo: placeholderView.trailingAnchor),
|
|
91
|
+
mainView.topAnchor.constraint(equalTo: placeholderView.topAnchor),
|
|
92
|
+
mainView.bottomAnchor.constraint(equalTo: placeholderView.bottomAnchor)
|
|
93
|
+
]
|
|
94
|
+
|
|
95
|
+
let constraintTop = stackView.topAnchor.constraint(equalTo: rootView.topAnchor)
|
|
96
|
+
let constraintBottom = stackView.bottomAnchor.constraint(equalTo: rootView.bottomAnchor)
|
|
97
|
+
constraintTop.priority = priortyLeast
|
|
98
|
+
constraintBottom.priority = priortyLeast
|
|
99
|
+
constraints += [
|
|
100
|
+
constraintBottom,
|
|
101
|
+
constraintTop
|
|
102
|
+
]
|
|
103
|
+
NSLayoutConstraint.activate(constraints)
|
|
104
|
+
|
|
105
|
+
rootObservation = rootView.observe(\.subviews, options: [.old, .new]) { (_, _) in
|
|
106
|
+
updateLayout()
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
private static func updateLayout() {
|
|
112
|
+
if let barView = Self.statusBarBackgroundView,
|
|
113
|
+
!barView.isHidden && rootView.subviews.contains(stackView) {
|
|
114
|
+
NSLayoutConstraint.activate([
|
|
115
|
+
stackView.topAnchor.constraint(equalTo: barView.bottomAnchor, constant: Self.marginTop ?? 0)
|
|
116
|
+
])
|
|
117
|
+
} else {
|
|
118
|
+
AMBBannerStackView.topConstraint.isActive = stackView.hasTopBanner
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
AMBBannerStackView.bottomConstraint.isActive = stackView.hasBottomBanner
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
let adSize: GADAdSize!
|
|
125
|
+
let position: String!
|
|
126
|
+
let offset: CGFloat?
|
|
127
|
+
var bannerView: GADBannerView!
|
|
128
|
+
let placeholder = AMBBannerPlaceholder()
|
|
129
|
+
|
|
130
|
+
init(id: Int, adUnitId: String, adSize: GADAdSize, adRequest: GADRequest, position: String, offset: CGFloat?) {
|
|
131
|
+
self.adSize = adSize
|
|
132
|
+
self.position = position
|
|
133
|
+
self.offset = offset
|
|
134
|
+
|
|
135
|
+
super.init(id: id, adUnitId: adUnitId, adRequest: adRequest)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
convenience init?(_ ctx: AMBContext) {
|
|
139
|
+
guard let id = ctx.optId(),
|
|
140
|
+
let adUnitId = ctx.optAdUnitID()
|
|
141
|
+
else {
|
|
142
|
+
return nil
|
|
143
|
+
}
|
|
144
|
+
self.init(id: id,
|
|
145
|
+
adUnitId: adUnitId,
|
|
146
|
+
adSize: ctx.optAdSize(),
|
|
147
|
+
adRequest: ctx.optGADRequest(),
|
|
148
|
+
position: ctx.optPosition(),
|
|
149
|
+
offset: ctx.optOffset())
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
deinit {
|
|
153
|
+
if bannerView != nil {
|
|
154
|
+
bannerView.delegate = nil
|
|
155
|
+
bannerView.adSizeDelegate = nil
|
|
156
|
+
Self.stackView.removeArrangedSubview(placeholder)
|
|
157
|
+
bannerView.removeFromSuperview()
|
|
158
|
+
bannerView = nil
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
override func isLoaded() -> Bool {
|
|
163
|
+
return bannerView != nil
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
override func load(_ ctx: AMBContext) {
|
|
167
|
+
if bannerView == nil {
|
|
168
|
+
bannerView = GADBannerView(adSize: self.adSize)
|
|
169
|
+
bannerView.delegate = self
|
|
170
|
+
bannerView.adSizeDelegate = self
|
|
171
|
+
bannerView.rootViewController = plugin.viewController
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
bannerView.adUnitID = adUnitId
|
|
175
|
+
bannerView.load(adRequest)
|
|
176
|
+
|
|
177
|
+
ctx.resolve()
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
override func show(_ ctx: AMBContext) {
|
|
181
|
+
if let offset = self.offset {
|
|
182
|
+
addBannerView(offset)
|
|
183
|
+
} else {
|
|
184
|
+
Self.prepareStackView()
|
|
185
|
+
|
|
186
|
+
switch position {
|
|
187
|
+
case AMBBannerPosition.top:
|
|
188
|
+
Self.stackView.insertArrangedSubview(placeholder, at: 0)
|
|
189
|
+
default:
|
|
190
|
+
Self.stackView.addArrangedSubview(placeholder)
|
|
191
|
+
}
|
|
192
|
+
Self.rootView.addSubview(bannerView)
|
|
193
|
+
|
|
194
|
+
bannerView.translatesAutoresizingMaskIntoConstraints = false
|
|
195
|
+
NSLayoutConstraint.activate([
|
|
196
|
+
placeholder.heightAnchor.constraint(equalTo: bannerView.heightAnchor),
|
|
197
|
+
bannerView.centerXAnchor.constraint(equalTo: placeholder.centerXAnchor),
|
|
198
|
+
bannerView.topAnchor.constraint(equalTo: placeholder.topAnchor),
|
|
199
|
+
bannerView.widthAnchor.constraint(equalTo: placeholder.widthAnchor)
|
|
200
|
+
])
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if bannerView.isHidden {
|
|
204
|
+
bannerView.isHidden = false
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
Self.updateLayout()
|
|
208
|
+
ctx.resolve()
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
override func hide(_ ctx: AMBContext) {
|
|
212
|
+
if bannerView != nil {
|
|
213
|
+
bannerView.isHidden = true
|
|
214
|
+
Self.stackView.removeArrangedSubview(placeholder)
|
|
215
|
+
Self.updateLayout()
|
|
216
|
+
}
|
|
217
|
+
ctx.resolve()
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
func bannerViewDidReceiveAd(_ bannerView: GADBannerView) {
|
|
221
|
+
self.emit(AMBEvents.adLoad, [
|
|
222
|
+
"size": [
|
|
223
|
+
"width": bannerView.frame.size.width,
|
|
224
|
+
"height": bannerView.frame.size.height,
|
|
225
|
+
"widthInPixels": round(bannerView.frame.size.width * UIScreen.main.scale),
|
|
226
|
+
"heightInPixels": round(bannerView.frame.size.height * UIScreen.main.scale)
|
|
227
|
+
]
|
|
228
|
+
])
|
|
229
|
+
self.emit(AMBEvents.bannerLoad)
|
|
230
|
+
self.emit(AMBEvents.bannerSize, [
|
|
231
|
+
"size": [
|
|
232
|
+
"width": bannerView.frame.size.width,
|
|
233
|
+
"height": bannerView.frame.size.height,
|
|
234
|
+
"widthInPixels": round(bannerView.frame.size.width * UIScreen.main.scale),
|
|
235
|
+
"heightInPixels": round(bannerView.frame.size.height * UIScreen.main.scale)
|
|
236
|
+
]
|
|
237
|
+
])
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
func bannerView(_ bannerView: GADBannerView,
|
|
241
|
+
didFailToReceiveAdWithError error: Error) {
|
|
242
|
+
self.emit(AMBEvents.adLoadFail, error)
|
|
243
|
+
self.emit(AMBEvents.bannerLoadFail, error)
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
func bannerViewDidRecordImpression(_ bannerView: GADBannerView) {
|
|
247
|
+
self.emit(AMBEvents.adImpression)
|
|
248
|
+
self.emit(AMBEvents.bannerImpression)
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
func bannerViewDidRecordClick(_ bannerView: GADBannerView) {
|
|
252
|
+
self.emit(AMBEvents.adClick)
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
func bannerViewWillPresentScreen(_ bannerView: GADBannerView) {
|
|
256
|
+
self.emit(AMBEvents.adShow)
|
|
257
|
+
self.emit(AMBEvents.bannerOpen)
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
func bannerViewWillDismissScreen(_ bannerView: GADBannerView) {
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
func bannerViewDidDismissScreen(_ bannerView: GADBannerView) {
|
|
264
|
+
self.emit(AMBEvents.adDismiss)
|
|
265
|
+
self.emit(AMBEvents.bannerClose)
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
func adView(_ bannerView: GADBannerView, willChangeAdSizeTo size: GADAdSize) {
|
|
269
|
+
self.emit(AMBEvents.bannerSizeChange, size)
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
private func addBannerView(_ offset: CGFloat) {
|
|
273
|
+
let rootView = Self.rootView
|
|
274
|
+
bannerView.translatesAutoresizingMaskIntoConstraints = false
|
|
275
|
+
rootView.addSubview(bannerView)
|
|
276
|
+
rootView.bringSubviewToFront(bannerView)
|
|
277
|
+
var constraints = [
|
|
278
|
+
bannerView.centerXAnchor.constraint(equalTo: rootView.centerXAnchor)
|
|
279
|
+
]
|
|
280
|
+
switch position {
|
|
281
|
+
case AMBBannerPosition.top:
|
|
282
|
+
constraints += [
|
|
283
|
+
bannerView.topAnchor.constraint(equalTo: rootView.topAnchor,
|
|
284
|
+
constant: offset)
|
|
285
|
+
]
|
|
286
|
+
default:
|
|
287
|
+
constraints += [
|
|
288
|
+
bannerView.bottomAnchor.constraint(equalTo: rootView.bottomAnchor,
|
|
289
|
+
constant: offset * -1)
|
|
290
|
+
]
|
|
291
|
+
}
|
|
292
|
+
NSLayoutConstraint.activate(constraints)
|
|
293
|
+
}
|
|
294
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import GoogleMobileAds
|
|
2
|
+
|
|
3
|
+
class AMBContext: AMBCoreContext {
|
|
4
|
+
func has(_ name: String) -> Bool {
|
|
5
|
+
return opts?.value(forKey: name) != nil
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
func optBool(_ name: String) -> Bool? {
|
|
9
|
+
return opt(name) as? Bool
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
func optFloat(_ name: String) -> Float? {
|
|
13
|
+
return opt(name) as? Float
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
func optInt(_ name: String) -> Int? {
|
|
17
|
+
return opt(name) as? Int
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
func optString(_ name: String, _ defaultValue: String) -> String {
|
|
21
|
+
if let v = opt(name) as? String {
|
|
22
|
+
return v
|
|
23
|
+
}
|
|
24
|
+
return defaultValue
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
func optStringArray(_ name: String) -> [String]? {
|
|
28
|
+
return opt(name) as? [String]
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
func resolve() {
|
|
32
|
+
self.sendResult(CDVPluginResult(status: CDVCommandStatus_OK))
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
func resolve(_ msg: Bool) {
|
|
36
|
+
self.sendResult(CDVPluginResult(status: CDVCommandStatus_OK, messageAs: msg))
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
func resolve(_ msg: UInt) {
|
|
40
|
+
self.sendResult(CDVPluginResult(status: CDVCommandStatus_OK, messageAs: msg))
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
func resolve(_ data: [String: Any]) {
|
|
44
|
+
self.sendResult(CDVPluginResult(status: CDVCommandStatus_OK, messageAs: data))
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
func reject(_ msg: String) {
|
|
48
|
+
self.sendResult(CDVPluginResult(status: CDVCommandStatus_ERROR, messageAs: msg))
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
static weak var plugin: AMBPlugin!
|
|
52
|
+
|
|
53
|
+
let command: CDVInvokedUrlCommand
|
|
54
|
+
|
|
55
|
+
init(_ command: CDVInvokedUrlCommand) {
|
|
56
|
+
self.command = command
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
var plugin: AMBPlugin {
|
|
60
|
+
return AMBContext.plugin
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
var commandDelegate: CDVCommandDelegate {
|
|
64
|
+
return plugin.commandDelegate
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
func opt0() -> Any? {
|
|
68
|
+
return command.argument(at: 0)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
lazy var opts: NSDictionary? = {
|
|
72
|
+
return opt0() as? NSDictionary
|
|
73
|
+
}()
|
|
74
|
+
|
|
75
|
+
func opt(_ key: String) -> Any? {
|
|
76
|
+
return opts?.value(forKey: key)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
func optOffset() -> CGFloat? {
|
|
80
|
+
return opt("offset") as? CGFloat
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
func optBackgroundColor() -> UIColor? {
|
|
84
|
+
if let bgColor = opt("backgroundColor") as? NSDictionary,
|
|
85
|
+
let r = bgColor["r"] as? CGFloat,
|
|
86
|
+
let g = bgColor["g"] as? CGFloat,
|
|
87
|
+
let b = bgColor["b"] as? CGFloat,
|
|
88
|
+
let a = bgColor["a"] as? CGFloat {
|
|
89
|
+
return UIColor(red: r / 255, green: g / 255, blue: b / 255, alpha: a / 255)
|
|
90
|
+
}
|
|
91
|
+
return nil
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
func optMarginTop() -> CGFloat? {
|
|
95
|
+
return opt("marginTop") as? CGFloat
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
func optMarginBottom() -> CGFloat? {
|
|
99
|
+
return opt("marginBottom") as? CGFloat
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// swiftlint:disable cyclomatic_complexity
|
|
103
|
+
func optAdSize() -> GADAdSize {
|
|
104
|
+
if let adSizeType = opt("size") as? Int {
|
|
105
|
+
switch adSizeType {
|
|
106
|
+
case 0:
|
|
107
|
+
return GADAdSizeBanner
|
|
108
|
+
case 1:
|
|
109
|
+
return GADAdSizeLargeBanner
|
|
110
|
+
case 2:
|
|
111
|
+
return GADAdSizeMediumRectangle
|
|
112
|
+
case 3:
|
|
113
|
+
return GADAdSizeFullBanner
|
|
114
|
+
case 4:
|
|
115
|
+
return GADAdSizeLeaderboard
|
|
116
|
+
default: break
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if let adSizeDict = opt("size") as? NSDictionary {
|
|
120
|
+
if let adaptive = adSizeDict["adaptive"] as? String {
|
|
121
|
+
var width = AMBHelper.frame.size.width
|
|
122
|
+
if let w = adSizeDict["width"] as? CGFloat {
|
|
123
|
+
width = w
|
|
124
|
+
}
|
|
125
|
+
if adaptive == "inline",
|
|
126
|
+
let maxHeight = adSizeDict["maxHeight"] as? CGFloat {
|
|
127
|
+
return GADInlineAdaptiveBannerAdSizeWithWidthAndMaxHeight(width, maxHeight)
|
|
128
|
+
} else {
|
|
129
|
+
switch adSizeDict["orientation"] as? String {
|
|
130
|
+
case "portrait":
|
|
131
|
+
return GADPortraitAnchoredAdaptiveBannerAdSizeWithWidth(width)
|
|
132
|
+
case "landscape":
|
|
133
|
+
return GADLandscapeAnchoredAdaptiveBannerAdSizeWithWidth(width)
|
|
134
|
+
default:
|
|
135
|
+
return GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(width)
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
} else if let width = adSizeDict["width"] as? Int,
|
|
139
|
+
let height = adSizeDict["height"] as? Int {
|
|
140
|
+
return GADAdSizeFromCGSize(CGSize(width: width, height: height))
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return GADAdSizeBanner
|
|
144
|
+
}
|
|
145
|
+
// swiftlint:enable cyclomatic_complexity
|
|
146
|
+
|
|
147
|
+
func optGADServerSideVerificationOptions() -> GADServerSideVerificationOptions? {
|
|
148
|
+
guard let ssv = opt("serverSideVerification") as? NSDictionary
|
|
149
|
+
else {
|
|
150
|
+
return nil
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
let options = GADServerSideVerificationOptions.init()
|
|
154
|
+
if let customData = ssv.value(forKey: "customData") as? String {
|
|
155
|
+
options.customRewardString = customData
|
|
156
|
+
}
|
|
157
|
+
if let userId = ssv.value(forKey: "userId") as? String {
|
|
158
|
+
options.userIdentifier = userId
|
|
159
|
+
}
|
|
160
|
+
return options
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
func sendResult(_ message: CDVPluginResult?) {
|
|
164
|
+
self.commandDelegate.send(message, callbackId: command.callbackId)
|
|
165
|
+
}
|
|
166
|
+
}
|