emi-indo-cordova-plugin-admob 1.2.9 → 1.4.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/.github/FUNDING.yml +13 -13
- package/.github/ISSUE_TEMPLATE/bug_report.md +124 -124
- package/LICENSE +7 -7
- package/README.md +509 -446
- package/example/Advanced topics/auto_load_and_show.html +94 -94
- package/example/Advanced topics/consent_GDPR_IAB_TFCv2.2.html +279 -0
- package/example/Advanced topics/targeting.html +78 -78
- package/example/app_open_ads.html +151 -151
- package/example/banner_ads.html +248 -248
- package/example/interstitial_ads.html +166 -166
- package/example/rewarded_ads.html +185 -185
- package/example/rewarded_interstitial_ads.html +184 -184
- package/package.json +34 -34
- package/plugin.xml +292 -284
- package/src/android/emiAdmobPlugin.java +1 -1
- package/src/ios/emiAdmobPlugin.swift +286 -286
- package/www/emiAdmobPlugin.js +8 -0
@@ -1,286 +1,286 @@
|
|
1
|
-
import Foundation
|
2
|
-
import GoogleMobileAds
|
3
|
-
import UIKit
|
4
|
-
|
5
|
-
@objc(emiAdmobPlugin)
|
6
|
-
public class emiAdmobPlugin : CDVPlugin, GADFullScreenContentDelegate, GADBannerViewDelegate {
|
7
|
-
|
8
|
-
private var bannerView: GADBannerView!
|
9
|
-
private var interstitial: GADInterstitialAd?
|
10
|
-
private var rewardedAd: GADRewardedAd?
|
11
|
-
private var rewardedInterstitialAd: GADRewardedInterstitialAd?
|
12
|
-
|
13
|
-
var isBannerShowing = false
|
14
|
-
|
15
|
-
|
16
|
-
@objc
|
17
|
-
func initialize(_ command: CDVInvokedUrlCommand) {
|
18
|
-
|
19
|
-
let ads = GADMobileAds.sharedInstance()
|
20
|
-
ads.start { status in
|
21
|
-
// Optional: Log each adapter's initialization latency.
|
22
|
-
let adapterStatuses = status.adapterStatusesByClassName
|
23
|
-
for adapter in adapterStatuses {
|
24
|
-
let adapterStatus = adapter.value
|
25
|
-
NSLog("Adapter Name: %@, Description: %@, Latency: %f", adapter.key,
|
26
|
-
adapterStatus.description, adapterStatus.latency)
|
27
|
-
}
|
28
|
-
let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "on.SdkInitializationComplete")
|
29
|
-
self.commandDelegate.send(pluginResult, callbackId: command.callbackId)
|
30
|
-
}
|
31
|
-
}
|
32
|
-
|
33
|
-
|
34
|
-
@objc
|
35
|
-
func showBannerAd(_ command: CDVInvokedUrlCommand) {
|
36
|
-
let bannerAdUnitId = command.arguments[0] as? String ?? ""
|
37
|
-
let position = command.arguments[1] as? String ?? ""
|
38
|
-
bannerView = GADBannerView(adSize: GADAdSizeBanner)
|
39
|
-
bannerView.adUnitID = bannerAdUnitId
|
40
|
-
bannerView.rootViewController = self.viewController
|
41
|
-
bannerView.load(GADRequest())
|
42
|
-
addBannerViewToView(bannerView, position, view: webView)
|
43
|
-
bannerView.delegate = self
|
44
|
-
}
|
45
|
-
|
46
|
-
|
47
|
-
func addBannerViewToView(_ bannerView: GADBannerView, _ position: String, view: UIView?) {
|
48
|
-
|
49
|
-
bannerView.translatesAutoresizingMaskIntoConstraints = false
|
50
|
-
view?.addSubview(bannerView)
|
51
|
-
if position == "top" {
|
52
|
-
|
53
|
-
view?.addConstraints(
|
54
|
-
[NSLayoutConstraint(item: bannerView,
|
55
|
-
attribute: .top,
|
56
|
-
relatedBy: .equal,
|
57
|
-
toItem: view?.safeAreaLayoutGuide,
|
58
|
-
attribute: .top,
|
59
|
-
multiplier: 1,
|
60
|
-
constant: 0),
|
61
|
-
NSLayoutConstraint(item: bannerView,
|
62
|
-
attribute: .centerX,
|
63
|
-
relatedBy: .equal,
|
64
|
-
toItem: view,
|
65
|
-
attribute: .centerX,
|
66
|
-
multiplier: 1,
|
67
|
-
constant: 0)
|
68
|
-
])
|
69
|
-
|
70
|
-
} else if position == "top-Margin" {
|
71
|
-
|
72
|
-
view?.addConstraints(
|
73
|
-
|
74
|
-
[NSLayoutConstraint(item: bannerView,
|
75
|
-
attribute: .topMargin,
|
76
|
-
relatedBy: .equal,
|
77
|
-
toItem: view?.safeAreaLayoutGuide,
|
78
|
-
attribute: .topMargin,
|
79
|
-
multiplier: 1,
|
80
|
-
constant: 0),
|
81
|
-
NSLayoutConstraint(item: bannerView,
|
82
|
-
attribute: .centerX,
|
83
|
-
relatedBy: .equal,
|
84
|
-
toItem: view,
|
85
|
-
attribute: .centerX,
|
86
|
-
multiplier: 1,
|
87
|
-
constant: 0)
|
88
|
-
])
|
89
|
-
|
90
|
-
} else if position == "bottom" {
|
91
|
-
|
92
|
-
view?.addConstraints(
|
93
|
-
|
94
|
-
[NSLayoutConstraint(item: bannerView,
|
95
|
-
attribute: .bottom,
|
96
|
-
relatedBy: .equal,
|
97
|
-
toItem: view?.safeAreaLayoutGuide,
|
98
|
-
attribute: .bottom,
|
99
|
-
multiplier: 1,
|
100
|
-
constant: 0),
|
101
|
-
NSLayoutConstraint(item: bannerView,
|
102
|
-
attribute: .centerX,
|
103
|
-
relatedBy: .equal,
|
104
|
-
toItem: view,
|
105
|
-
attribute: .centerX,
|
106
|
-
multiplier: 1,
|
107
|
-
constant: 0)
|
108
|
-
])
|
109
|
-
|
110
|
-
|
111
|
-
} else if position == "bottom-Margin" {
|
112
|
-
|
113
|
-
view?.addConstraints(
|
114
|
-
|
115
|
-
[NSLayoutConstraint(item: bannerView,
|
116
|
-
attribute: .bottomMargin,
|
117
|
-
relatedBy: .equal,
|
118
|
-
toItem: view?.safeAreaLayoutGuide,
|
119
|
-
attribute: .bottomMargin,
|
120
|
-
multiplier: 1,
|
121
|
-
constant: 0),
|
122
|
-
NSLayoutConstraint(item: bannerView,
|
123
|
-
attribute: .centerX,
|
124
|
-
relatedBy: .equal,
|
125
|
-
toItem: view,
|
126
|
-
attribute: .centerX,
|
127
|
-
multiplier: 1,
|
128
|
-
constant: 0)
|
129
|
-
])
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
} else {
|
134
|
-
|
135
|
-
|
136
|
-
view?.addConstraints(
|
137
|
-
|
138
|
-
[NSLayoutConstraint(item: bannerView,
|
139
|
-
attribute: .bottomMargin,
|
140
|
-
relatedBy: .equal,
|
141
|
-
toItem: view?.safeAreaLayoutGuide,
|
142
|
-
attribute: .bottomMargin,
|
143
|
-
multiplier: 1,
|
144
|
-
constant: 0),
|
145
|
-
NSLayoutConstraint(item: bannerView,
|
146
|
-
attribute: .centerX,
|
147
|
-
relatedBy: .equal,
|
148
|
-
toItem: view,
|
149
|
-
attribute: .centerX,
|
150
|
-
multiplier: 1,
|
151
|
-
constant: 0)
|
152
|
-
])
|
153
|
-
}
|
154
|
-
}
|
155
|
-
|
156
|
-
|
157
|
-
@objc
|
158
|
-
func removeBannerAd(_ command: CDVInvokedUrlCommand) {
|
159
|
-
|
160
|
-
if(bannerView != nil){
|
161
|
-
self.isBannerShowing = true;
|
162
|
-
}
|
163
|
-
|
164
|
-
if(self.isBannerShowing){
|
165
|
-
|
166
|
-
self.isBannerShowing = self.unLoadBanner(self.bannerView)
|
167
|
-
}
|
168
|
-
}
|
169
|
-
|
170
|
-
func unLoadBanner(_ bannerView: UIView?) -> Bool{
|
171
|
-
bannerView?.removeFromSuperview()
|
172
|
-
return false
|
173
|
-
}
|
174
|
-
|
175
|
-
|
176
|
-
@objc
|
177
|
-
func loadInterstitialAd(_ command: CDVInvokedUrlCommand) {
|
178
|
-
|
179
|
-
let interstitialAdAdUnitId = command.arguments[0] as? String ?? ""
|
180
|
-
|
181
|
-
let request = GADRequest()
|
182
|
-
GADInterstitialAd.load(withAdUnitID: interstitialAdAdUnitId,
|
183
|
-
request: request,
|
184
|
-
completionHandler: { [self] ad, error in
|
185
|
-
if let error = error {
|
186
|
-
print("Failed to load interstitial ad with error: \(error.localizedDescription)")
|
187
|
-
let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "on.InterstitialAdFailedToLoad")
|
188
|
-
self.commandDelegate.send(pluginResult, callbackId: command.callbackId)
|
189
|
-
return
|
190
|
-
}
|
191
|
-
|
192
|
-
self.interstitial = ad
|
193
|
-
self.interstitial?.fullScreenContentDelegate = self
|
194
|
-
|
195
|
-
let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "on.InterstitialAdLoaded")
|
196
|
-
self.commandDelegate.send(pluginResult, callbackId: command.callbackId)
|
197
|
-
|
198
|
-
} )
|
199
|
-
|
200
|
-
}
|
201
|
-
|
202
|
-
@objc
|
203
|
-
func showInterstitialAd(_ command: CDVInvokedUrlCommand) {
|
204
|
-
if interstitial != nil {
|
205
|
-
interstitial?.present(fromRootViewController: self.viewController)
|
206
|
-
} else {
|
207
|
-
print("Ad wasn't ready")
|
208
|
-
}
|
209
|
-
}
|
210
|
-
|
211
|
-
@objc
|
212
|
-
func loadRewardedAd(_ command: CDVInvokedUrlCommand) {
|
213
|
-
let rewardedAdAdUnitId = command.arguments[0] as? String ?? ""
|
214
|
-
let request = GADRequest()
|
215
|
-
GADRewardedAd.load(
|
216
|
-
withAdUnitID:rewardedAdAdUnitId,
|
217
|
-
request: request,
|
218
|
-
completionHandler: {
|
219
|
-
[self] ad, error in
|
220
|
-
if let error = error {
|
221
|
-
print("Failed to load rewarded ad with error: \(error.localizedDescription)")
|
222
|
-
let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "on.RewardedAdFailedToLoad")
|
223
|
-
self.commandDelegate.send(pluginResult, callbackId: command.callbackId)
|
224
|
-
return
|
225
|
-
}
|
226
|
-
rewardedAd = ad
|
227
|
-
print("Rewarded ad loaded.")
|
228
|
-
|
229
|
-
let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "on.RewardedAdLoaded")
|
230
|
-
self.commandDelegate.send(pluginResult, callbackId: command.callbackId)
|
231
|
-
}
|
232
|
-
)
|
233
|
-
}
|
234
|
-
|
235
|
-
@objc
|
236
|
-
func showRewardedAd(_ command: CDVInvokedUrlCommand) {
|
237
|
-
|
238
|
-
if let ad = rewardedAd {
|
239
|
-
ad.present(fromRootViewController: self.viewController) {
|
240
|
-
let reward = ad.adReward
|
241
|
-
print("Reward received with currency \(reward.amount), amount \(reward.amount.doubleValue)")
|
242
|
-
// TODO: Reward the user.
|
243
|
-
let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "on.rewarded.rewarded")
|
244
|
-
self.commandDelegate.send(pluginResult, callbackId: command.callbackId)
|
245
|
-
}
|
246
|
-
} else {
|
247
|
-
print("Ad wasn't ready")
|
248
|
-
}
|
249
|
-
}
|
250
|
-
|
251
|
-
|
252
|
-
@objc
|
253
|
-
func loadRewardedInterstitialAd(_ command: CDVInvokedUrlCommand) {
|
254
|
-
let interstitialAdAdUnitId = command.arguments[0] as? String ?? ""
|
255
|
-
GADRewardedInterstitialAd.load(
|
256
|
-
withAdUnitID:interstitialAdAdUnitId,
|
257
|
-
request: GADRequest()) { ad, error in
|
258
|
-
if let error = error {
|
259
|
-
return print("Failed to load rewarded interstitial ad with error: \(error.localizedDescription)")
|
260
|
-
let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "on.RewardedInterstitialAdFailedToLoad")
|
261
|
-
self.commandDelegate.send(pluginResult, callbackId: command.callbackId)
|
262
|
-
}
|
263
|
-
self.rewardedInterstitialAd = ad
|
264
|
-
let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "on.RewardedInterstitialAdLoaded")
|
265
|
-
self.commandDelegate.send(pluginResult, callbackId: command.callbackId)
|
266
|
-
}
|
267
|
-
}
|
268
|
-
|
269
|
-
@objc
|
270
|
-
func showRewardedInterstitialAd(_ command: CDVInvokedUrlCommand) {
|
271
|
-
|
272
|
-
if rewardedInterstitialAd != nil {
|
273
|
-
rewardedInterstitialAd?.present(fromRootViewController: self.viewController) {
|
274
|
-
// let reward = rewardedInterstitialAd?.adReward
|
275
|
-
// TODO: Reward the user!
|
276
|
-
let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "on.rewardedInterstitial.rewarded")
|
277
|
-
self.commandDelegate.send(pluginResult, callbackId: command.callbackId)
|
278
|
-
}
|
279
|
-
} else {
|
280
|
-
print("Ad wasn't ready")
|
281
|
-
}
|
282
|
-
}
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
}
|
1
|
+
import Foundation
|
2
|
+
import GoogleMobileAds
|
3
|
+
import UIKit
|
4
|
+
|
5
|
+
@objc(emiAdmobPlugin)
|
6
|
+
public class emiAdmobPlugin : CDVPlugin, GADFullScreenContentDelegate, GADBannerViewDelegate {
|
7
|
+
|
8
|
+
private var bannerView: GADBannerView!
|
9
|
+
private var interstitial: GADInterstitialAd?
|
10
|
+
private var rewardedAd: GADRewardedAd?
|
11
|
+
private var rewardedInterstitialAd: GADRewardedInterstitialAd?
|
12
|
+
|
13
|
+
var isBannerShowing = false
|
14
|
+
|
15
|
+
|
16
|
+
@objc
|
17
|
+
func initialize(_ command: CDVInvokedUrlCommand) {
|
18
|
+
|
19
|
+
let ads = GADMobileAds.sharedInstance()
|
20
|
+
ads.start { status in
|
21
|
+
// Optional: Log each adapter's initialization latency.
|
22
|
+
let adapterStatuses = status.adapterStatusesByClassName
|
23
|
+
for adapter in adapterStatuses {
|
24
|
+
let adapterStatus = adapter.value
|
25
|
+
NSLog("Adapter Name: %@, Description: %@, Latency: %f", adapter.key,
|
26
|
+
adapterStatus.description, adapterStatus.latency)
|
27
|
+
}
|
28
|
+
let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "on.SdkInitializationComplete")
|
29
|
+
self.commandDelegate.send(pluginResult, callbackId: command.callbackId)
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
|
34
|
+
@objc
|
35
|
+
func showBannerAd(_ command: CDVInvokedUrlCommand) {
|
36
|
+
let bannerAdUnitId = command.arguments[0] as? String ?? ""
|
37
|
+
let position = command.arguments[1] as? String ?? ""
|
38
|
+
bannerView = GADBannerView(adSize: GADAdSizeBanner)
|
39
|
+
bannerView.adUnitID = bannerAdUnitId
|
40
|
+
bannerView.rootViewController = self.viewController
|
41
|
+
bannerView.load(GADRequest())
|
42
|
+
addBannerViewToView(bannerView, position, view: webView)
|
43
|
+
bannerView.delegate = self
|
44
|
+
}
|
45
|
+
|
46
|
+
|
47
|
+
func addBannerViewToView(_ bannerView: GADBannerView, _ position: String, view: UIView?) {
|
48
|
+
|
49
|
+
bannerView.translatesAutoresizingMaskIntoConstraints = false
|
50
|
+
view?.addSubview(bannerView)
|
51
|
+
if position == "top" {
|
52
|
+
|
53
|
+
view?.addConstraints(
|
54
|
+
[NSLayoutConstraint(item: bannerView,
|
55
|
+
attribute: .top,
|
56
|
+
relatedBy: .equal,
|
57
|
+
toItem: view?.safeAreaLayoutGuide,
|
58
|
+
attribute: .top,
|
59
|
+
multiplier: 1,
|
60
|
+
constant: 0),
|
61
|
+
NSLayoutConstraint(item: bannerView,
|
62
|
+
attribute: .centerX,
|
63
|
+
relatedBy: .equal,
|
64
|
+
toItem: view,
|
65
|
+
attribute: .centerX,
|
66
|
+
multiplier: 1,
|
67
|
+
constant: 0)
|
68
|
+
])
|
69
|
+
|
70
|
+
} else if position == "top-Margin" {
|
71
|
+
|
72
|
+
view?.addConstraints(
|
73
|
+
|
74
|
+
[NSLayoutConstraint(item: bannerView,
|
75
|
+
attribute: .topMargin,
|
76
|
+
relatedBy: .equal,
|
77
|
+
toItem: view?.safeAreaLayoutGuide,
|
78
|
+
attribute: .topMargin,
|
79
|
+
multiplier: 1,
|
80
|
+
constant: 0),
|
81
|
+
NSLayoutConstraint(item: bannerView,
|
82
|
+
attribute: .centerX,
|
83
|
+
relatedBy: .equal,
|
84
|
+
toItem: view,
|
85
|
+
attribute: .centerX,
|
86
|
+
multiplier: 1,
|
87
|
+
constant: 0)
|
88
|
+
])
|
89
|
+
|
90
|
+
} else if position == "bottom" {
|
91
|
+
|
92
|
+
view?.addConstraints(
|
93
|
+
|
94
|
+
[NSLayoutConstraint(item: bannerView,
|
95
|
+
attribute: .bottom,
|
96
|
+
relatedBy: .equal,
|
97
|
+
toItem: view?.safeAreaLayoutGuide,
|
98
|
+
attribute: .bottom,
|
99
|
+
multiplier: 1,
|
100
|
+
constant: 0),
|
101
|
+
NSLayoutConstraint(item: bannerView,
|
102
|
+
attribute: .centerX,
|
103
|
+
relatedBy: .equal,
|
104
|
+
toItem: view,
|
105
|
+
attribute: .centerX,
|
106
|
+
multiplier: 1,
|
107
|
+
constant: 0)
|
108
|
+
])
|
109
|
+
|
110
|
+
|
111
|
+
} else if position == "bottom-Margin" {
|
112
|
+
|
113
|
+
view?.addConstraints(
|
114
|
+
|
115
|
+
[NSLayoutConstraint(item: bannerView,
|
116
|
+
attribute: .bottomMargin,
|
117
|
+
relatedBy: .equal,
|
118
|
+
toItem: view?.safeAreaLayoutGuide,
|
119
|
+
attribute: .bottomMargin,
|
120
|
+
multiplier: 1,
|
121
|
+
constant: 0),
|
122
|
+
NSLayoutConstraint(item: bannerView,
|
123
|
+
attribute: .centerX,
|
124
|
+
relatedBy: .equal,
|
125
|
+
toItem: view,
|
126
|
+
attribute: .centerX,
|
127
|
+
multiplier: 1,
|
128
|
+
constant: 0)
|
129
|
+
])
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
} else {
|
134
|
+
|
135
|
+
|
136
|
+
view?.addConstraints(
|
137
|
+
|
138
|
+
[NSLayoutConstraint(item: bannerView,
|
139
|
+
attribute: .bottomMargin,
|
140
|
+
relatedBy: .equal,
|
141
|
+
toItem: view?.safeAreaLayoutGuide,
|
142
|
+
attribute: .bottomMargin,
|
143
|
+
multiplier: 1,
|
144
|
+
constant: 0),
|
145
|
+
NSLayoutConstraint(item: bannerView,
|
146
|
+
attribute: .centerX,
|
147
|
+
relatedBy: .equal,
|
148
|
+
toItem: view,
|
149
|
+
attribute: .centerX,
|
150
|
+
multiplier: 1,
|
151
|
+
constant: 0)
|
152
|
+
])
|
153
|
+
}
|
154
|
+
}
|
155
|
+
|
156
|
+
|
157
|
+
@objc
|
158
|
+
func removeBannerAd(_ command: CDVInvokedUrlCommand) {
|
159
|
+
|
160
|
+
if(bannerView != nil){
|
161
|
+
self.isBannerShowing = true;
|
162
|
+
}
|
163
|
+
|
164
|
+
if(self.isBannerShowing){
|
165
|
+
|
166
|
+
self.isBannerShowing = self.unLoadBanner(self.bannerView)
|
167
|
+
}
|
168
|
+
}
|
169
|
+
|
170
|
+
func unLoadBanner(_ bannerView: UIView?) -> Bool{
|
171
|
+
bannerView?.removeFromSuperview()
|
172
|
+
return false
|
173
|
+
}
|
174
|
+
|
175
|
+
|
176
|
+
@objc
|
177
|
+
func loadInterstitialAd(_ command: CDVInvokedUrlCommand) {
|
178
|
+
|
179
|
+
let interstitialAdAdUnitId = command.arguments[0] as? String ?? ""
|
180
|
+
|
181
|
+
let request = GADRequest()
|
182
|
+
GADInterstitialAd.load(withAdUnitID: interstitialAdAdUnitId,
|
183
|
+
request: request,
|
184
|
+
completionHandler: { [self] ad, error in
|
185
|
+
if let error = error {
|
186
|
+
print("Failed to load interstitial ad with error: \(error.localizedDescription)")
|
187
|
+
let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "on.InterstitialAdFailedToLoad")
|
188
|
+
self.commandDelegate.send(pluginResult, callbackId: command.callbackId)
|
189
|
+
return
|
190
|
+
}
|
191
|
+
|
192
|
+
self.interstitial = ad
|
193
|
+
self.interstitial?.fullScreenContentDelegate = self
|
194
|
+
|
195
|
+
let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "on.InterstitialAdLoaded")
|
196
|
+
self.commandDelegate.send(pluginResult, callbackId: command.callbackId)
|
197
|
+
|
198
|
+
} )
|
199
|
+
|
200
|
+
}
|
201
|
+
|
202
|
+
@objc
|
203
|
+
func showInterstitialAd(_ command: CDVInvokedUrlCommand) {
|
204
|
+
if interstitial != nil {
|
205
|
+
interstitial?.present(fromRootViewController: self.viewController)
|
206
|
+
} else {
|
207
|
+
print("Ad wasn't ready")
|
208
|
+
}
|
209
|
+
}
|
210
|
+
|
211
|
+
@objc
|
212
|
+
func loadRewardedAd(_ command: CDVInvokedUrlCommand) {
|
213
|
+
let rewardedAdAdUnitId = command.arguments[0] as? String ?? ""
|
214
|
+
let request = GADRequest()
|
215
|
+
GADRewardedAd.load(
|
216
|
+
withAdUnitID:rewardedAdAdUnitId,
|
217
|
+
request: request,
|
218
|
+
completionHandler: {
|
219
|
+
[self] ad, error in
|
220
|
+
if let error = error {
|
221
|
+
print("Failed to load rewarded ad with error: \(error.localizedDescription)")
|
222
|
+
let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "on.RewardedAdFailedToLoad")
|
223
|
+
self.commandDelegate.send(pluginResult, callbackId: command.callbackId)
|
224
|
+
return
|
225
|
+
}
|
226
|
+
rewardedAd = ad
|
227
|
+
print("Rewarded ad loaded.")
|
228
|
+
|
229
|
+
let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "on.RewardedAdLoaded")
|
230
|
+
self.commandDelegate.send(pluginResult, callbackId: command.callbackId)
|
231
|
+
}
|
232
|
+
)
|
233
|
+
}
|
234
|
+
|
235
|
+
@objc
|
236
|
+
func showRewardedAd(_ command: CDVInvokedUrlCommand) {
|
237
|
+
|
238
|
+
if let ad = rewardedAd {
|
239
|
+
ad.present(fromRootViewController: self.viewController) {
|
240
|
+
let reward = ad.adReward
|
241
|
+
print("Reward received with currency \(reward.amount), amount \(reward.amount.doubleValue)")
|
242
|
+
// TODO: Reward the user.
|
243
|
+
let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "on.rewarded.rewarded")
|
244
|
+
self.commandDelegate.send(pluginResult, callbackId: command.callbackId)
|
245
|
+
}
|
246
|
+
} else {
|
247
|
+
print("Ad wasn't ready")
|
248
|
+
}
|
249
|
+
}
|
250
|
+
|
251
|
+
|
252
|
+
@objc
|
253
|
+
func loadRewardedInterstitialAd(_ command: CDVInvokedUrlCommand) {
|
254
|
+
let interstitialAdAdUnitId = command.arguments[0] as? String ?? ""
|
255
|
+
GADRewardedInterstitialAd.load(
|
256
|
+
withAdUnitID:interstitialAdAdUnitId,
|
257
|
+
request: GADRequest()) { ad, error in
|
258
|
+
if let error = error {
|
259
|
+
return print("Failed to load rewarded interstitial ad with error: \(error.localizedDescription)")
|
260
|
+
let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "on.RewardedInterstitialAdFailedToLoad")
|
261
|
+
self.commandDelegate.send(pluginResult, callbackId: command.callbackId)
|
262
|
+
}
|
263
|
+
self.rewardedInterstitialAd = ad
|
264
|
+
let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "on.RewardedInterstitialAdLoaded")
|
265
|
+
self.commandDelegate.send(pluginResult, callbackId: command.callbackId)
|
266
|
+
}
|
267
|
+
}
|
268
|
+
|
269
|
+
@objc
|
270
|
+
func showRewardedInterstitialAd(_ command: CDVInvokedUrlCommand) {
|
271
|
+
|
272
|
+
if rewardedInterstitialAd != nil {
|
273
|
+
rewardedInterstitialAd?.present(fromRootViewController: self.viewController) {
|
274
|
+
// let reward = rewardedInterstitialAd?.adReward
|
275
|
+
// TODO: Reward the user!
|
276
|
+
let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "on.rewardedInterstitial.rewarded")
|
277
|
+
self.commandDelegate.send(pluginResult, callbackId: command.callbackId)
|
278
|
+
}
|
279
|
+
} else {
|
280
|
+
print("Ad wasn't ready")
|
281
|
+
}
|
282
|
+
}
|
283
|
+
|
284
|
+
|
285
|
+
|
286
|
+
}
|
package/www/emiAdmobPlugin.js
CHANGED
@@ -4,6 +4,14 @@ exports.initialize = function (success, error) {
|
|
4
4
|
exec(success, error, 'emiAdmobPlugin', 'initialize', []);
|
5
5
|
};
|
6
6
|
|
7
|
+
exports.getIabTfc = function (success, error) {
|
8
|
+
exec(success, error, 'emiAdmobPlugin', 'getIabTfc', []);
|
9
|
+
};
|
10
|
+
|
11
|
+
exports.showPrivacyOptionsForm = function (success, error) {
|
12
|
+
exec(success, error, 'emiAdmobPlugin', 'showPrivacyOptionsForm', []);
|
13
|
+
};
|
14
|
+
|
7
15
|
exports.loadAppOpenAd = function (arg0, arg1, arg2, success, error) {
|
8
16
|
exec(success, error, 'emiAdmobPlugin', 'loadAppOpenAd', [arg0, arg1, arg2]);
|
9
17
|
};
|