emi-indo-cordova-plugin-admob 0.0.4 → 0.0.6

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.
@@ -0,0 +1,258 @@
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
+
14
+ @objc
15
+ func initialize(_ command: CDVInvokedUrlCommand) {
16
+
17
+ GADMobileAds.sharedInstance().start(completionHandler: nil)
18
+
19
+ let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "on.SdkInitializationComplete")
20
+ self.commandDelegate.send(pluginResult, callbackId: command.callbackId)
21
+
22
+ }
23
+
24
+
25
+ @objc
26
+ func showbannerAd(_ command: CDVInvokedUrlCommand) {
27
+ let bannerAdUnitId = command.arguments[0] as? String ?? ""
28
+ let position = command.arguments[1] as? String ?? ""
29
+ bannerView = GADBannerView(adSize: GADAdSizeBanner)
30
+ bannerView.adUnitID = bannerAdUnitId
31
+ bannerView.rootViewController = self.viewController
32
+ bannerView.load(GADRequest())
33
+ addBannerViewToView(bannerView, position, view: webView)
34
+ bannerView.delegate = self
35
+ }
36
+
37
+
38
+ func addBannerViewToView(_ bannerView: GADBannerView, _ position: String, view: UIView?) {
39
+
40
+ bannerView.translatesAutoresizingMaskIntoConstraints = false
41
+ view?.addSubview(bannerView)
42
+ if position == "top" {
43
+
44
+ view?.addConstraints(
45
+ [NSLayoutConstraint(item: bannerView,
46
+ attribute: .top,
47
+ relatedBy: .equal,
48
+ toItem: view?.safeAreaLayoutGuide,
49
+ attribute: .top,
50
+ multiplier: 1,
51
+ constant: 0),
52
+ NSLayoutConstraint(item: bannerView,
53
+ attribute: .centerX,
54
+ relatedBy: .equal,
55
+ toItem: view,
56
+ attribute: .centerX,
57
+ multiplier: 1,
58
+ constant: 0)
59
+ ])
60
+
61
+ } else if position == "top-Margin" {
62
+
63
+ view?.addConstraints(
64
+
65
+ [NSLayoutConstraint(item: bannerView,
66
+ attribute: .topMargin,
67
+ relatedBy: .equal,
68
+ toItem: view?.safeAreaLayoutGuide,
69
+ attribute: .topMargin,
70
+ multiplier: 1,
71
+ constant: 0),
72
+ NSLayoutConstraint(item: bannerView,
73
+ attribute: .centerX,
74
+ relatedBy: .equal,
75
+ toItem: view,
76
+ attribute: .centerX,
77
+ multiplier: 1,
78
+ constant: 0)
79
+ ])
80
+
81
+ } else if position == "bottom" {
82
+
83
+ view?.addConstraints(
84
+
85
+ [NSLayoutConstraint(item: bannerView,
86
+ attribute: .bottom,
87
+ relatedBy: .equal,
88
+ toItem: view?.safeAreaLayoutGuide,
89
+ attribute: .bottom,
90
+ multiplier: 1,
91
+ constant: 0),
92
+ NSLayoutConstraint(item: bannerView,
93
+ attribute: .centerX,
94
+ relatedBy: .equal,
95
+ toItem: view,
96
+ attribute: .centerX,
97
+ multiplier: 1,
98
+ constant: 0)
99
+ ])
100
+
101
+
102
+ } else if position == "bottom-Margin" {
103
+
104
+ view?.addConstraints(
105
+
106
+ [NSLayoutConstraint(item: bannerView,
107
+ attribute: .bottomMargin,
108
+ relatedBy: .equal,
109
+ toItem: view?.safeAreaLayoutGuide,
110
+ attribute: .bottomMargin,
111
+ multiplier: 1,
112
+ constant: 0),
113
+ NSLayoutConstraint(item: bannerView,
114
+ attribute: .centerX,
115
+ relatedBy: .equal,
116
+ toItem: view,
117
+ attribute: .centerX,
118
+ multiplier: 1,
119
+ constant: 0)
120
+ ])
121
+
122
+
123
+
124
+ } else {
125
+
126
+
127
+ view?.addConstraints(
128
+
129
+ [NSLayoutConstraint(item: bannerView,
130
+ attribute: .bottomMargin,
131
+ relatedBy: .equal,
132
+ toItem: view?.safeAreaLayoutGuide,
133
+ attribute: .bottomMargin,
134
+ multiplier: 1,
135
+ constant: 0),
136
+ NSLayoutConstraint(item: bannerView,
137
+ attribute: .centerX,
138
+ relatedBy: .equal,
139
+ toItem: view,
140
+ attribute: .centerX,
141
+ multiplier: 1,
142
+ constant: 0)
143
+ ])
144
+ }
145
+ }
146
+
147
+
148
+ @objc
149
+ func loadInterstitialAd(_ command: CDVInvokedUrlCommand) {
150
+
151
+ let interstitialAdAdUnitId = command.arguments[0] as? String ?? ""
152
+
153
+ let request = GADRequest()
154
+ GADInterstitialAd.load(withAdUnitID: interstitialAdAdUnitId,
155
+ request: request,
156
+ completionHandler: { [self] ad, error in
157
+ if let error = error {
158
+ print("Failed to load interstitial ad with error: \(error.localizedDescription)")
159
+ let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "on.InterstitialAdFailedToLoad")
160
+ self.commandDelegate.send(pluginResult, callbackId: command.callbackId)
161
+ return
162
+ }
163
+
164
+ self.interstitial = ad
165
+ self.interstitial?.fullScreenContentDelegate = self
166
+
167
+ let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "on.InterstitialAdLoaded")
168
+ self.commandDelegate.send(pluginResult, callbackId: command.callbackId)
169
+
170
+ } )
171
+
172
+ }
173
+
174
+ @objc
175
+ func showInterstitialAd(_ command: CDVInvokedUrlCommand) {
176
+ if interstitial != nil {
177
+ interstitial?.present(fromRootViewController: self.viewController)
178
+ } else {
179
+ print("Ad wasn't ready")
180
+ }
181
+ }
182
+
183
+ @objc
184
+ func loadRewardedAd(_ command: CDVInvokedUrlCommand) {
185
+ let rewardedAdAdUnitId = command.arguments[0] as? String ?? ""
186
+ let request = GADRequest()
187
+ GADRewardedAd.load(
188
+ withAdUnitID:rewardedAdAdUnitId,
189
+ request: request,
190
+ completionHandler: {
191
+ [self] ad, error in
192
+ if let error = error {
193
+ print("Failed to load rewarded ad with error: \(error.localizedDescription)")
194
+ let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "on.RewardedAdFailedToLoad")
195
+ self.commandDelegate.send(pluginResult, callbackId: command.callbackId)
196
+ return
197
+ }
198
+ rewardedAd = ad
199
+ print("Rewarded ad loaded.")
200
+
201
+ let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "on.RewardedAdLoaded")
202
+ self.commandDelegate.send(pluginResult, callbackId: command.callbackId)
203
+ }
204
+ )
205
+ }
206
+
207
+ @objc
208
+ func showRewardedAd(_ command: CDVInvokedUrlCommand) {
209
+
210
+ if let ad = rewardedAd {
211
+ ad.present(fromRootViewController: self.viewController) {
212
+ let reward = ad.adReward
213
+ print("Reward received with currency \(reward.amount), amount \(reward.amount.doubleValue)")
214
+ // TODO: Reward the user.
215
+ let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "on.rewarded.rewarded")
216
+ self.commandDelegate.send(pluginResult, callbackId: command.callbackId)
217
+ }
218
+ } else {
219
+ print("Ad wasn't ready")
220
+ }
221
+ }
222
+
223
+
224
+ @objc
225
+ func loadRewardedInterstitialAd(_ command: CDVInvokedUrlCommand) {
226
+ let interstitialAdAdUnitId = command.arguments[0] as? String ?? ""
227
+ GADRewardedInterstitialAd.load(
228
+ withAdUnitID:interstitialAdAdUnitId,
229
+ request: GADRequest()) { ad, error in
230
+ if let error = error {
231
+ return print("Failed to load rewarded interstitial ad with error: \(error.localizedDescription)")
232
+ let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "on.RewardedInterstitialAdFailedToLoad")
233
+ self.commandDelegate.send(pluginResult, callbackId: command.callbackId)
234
+ }
235
+ self.rewardedInterstitialAd = ad
236
+ let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "on.RewardedInterstitialAdLoaded")
237
+ self.commandDelegate.send(pluginResult, callbackId: command.callbackId)
238
+ }
239
+ }
240
+
241
+ @objc
242
+ func showRewardedInterstitialAd(_ command: CDVInvokedUrlCommand) {
243
+
244
+ if rewardedInterstitialAd != nil {
245
+ rewardedInterstitialAd?.present(fromRootViewController: self.viewController) {
246
+ // let reward = rewardedInterstitialAd?.adReward
247
+ // TODO: Reward the user!
248
+ let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "on.rewardedInterstitial.rewarded")
249
+ self.commandDelegate.send(pluginResult, callbackId: command.callbackId)
250
+ }
251
+ } else {
252
+ print("Ad wasn't ready")
253
+ }
254
+ }
255
+
256
+
257
+
258
+ }
@@ -1,38 +1,49 @@
1
1
  var exec = require('cordova/exec');
2
2
 
3
-
4
3
  exports.initialize = function (arg0, success, error) {
5
4
  exec(success, error, 'emiAdmobPlugin', 'initialize', [arg0]);
6
5
  };
7
6
 
8
- exports.showBannerAd = function (bannerAdUnitId, size, position, adaptiveWidth, success, error) {
9
- exec(success, error, 'emiAdmobPlugin', 'showBannerAd', [bannerAdUnitId, size, position, adaptiveWidth]);
7
+ exports.showBannerAd = function (arg0, arg1, arg2, arg3, arg4, success, error) {
8
+ exec(success, error, 'emiAdmobPlugin', 'showBannerAd', [arg0, arg1, arg2, arg3, arg4]);
10
9
  };
11
10
 
12
11
  exports.removeBannerAd = function (arg0, success, error) {
13
12
  exec(success, error, 'emiAdmobPlugin', 'removeBannerAd', [arg0]);
14
13
  };
15
14
 
16
- exports.loadInterstitialAd = function (arg0, success, error) {
17
- exec(success, error, 'emiAdmobPlugin', 'loadInterstitialAd', [arg0]);
15
+ exports.loadInterstitialAd = function (arg0, arg1, arg2, success, error) {
16
+ exec(success, error, 'emiAdmobPlugin', 'loadInterstitialAd', [arg0, arg1, arg2]);
18
17
  };
19
18
 
20
19
  exports.showInterstitialAd = function (arg0, success, error) {
21
20
  exec(success, error, 'emiAdmobPlugin', 'showInterstitialAd', [arg0]);
22
21
  };
23
22
 
24
- exports.loadRewardedAd = function (arg0, success, error) {
25
- exec(success, error, 'emiAdmobPlugin', 'loadRewardedAd', [arg0]);
23
+ exports.loadRewardedAd = function (arg0, arg1, arg2, success, error) {
24
+ exec(success, error, 'emiAdmobPlugin', 'loadRewardedAd', [arg0, arg1, arg2]);
26
25
  };
27
26
 
28
27
  exports.showRewardedAd = function (arg0, success, error) {
29
28
  exec(success, error, 'emiAdmobPlugin', 'showRewardedAd', [arg0]);
30
29
  };
31
30
 
32
- exports.loadRewardedInterstitialAd = function (arg0, success, error) {
33
- exec(success, error, 'emiAdmobPlugin', 'loadRewardedInterstitialAd', [arg0]);
31
+ exports.loadRewardedInterstitialAd = function (arg0, arg1, arg2, success, error) {
32
+ exec(success, error, 'emiAdmobPlugin', 'loadRewardedInterstitialAd', [arg0, arg1, arg2]);
34
33
  };
35
34
 
36
35
  exports.showRewardedInterstitialAd = function (arg0, success, error) {
37
36
  exec(success, error, 'emiAdmobPlugin', 'showRewardedInterstitialAd', [arg0]);
37
+ };
38
+
39
+ exports.getConsentRequest = function (arg0, success, error) {
40
+ exec(success, error, 'emiAdmobPlugin', 'getConsentRequest', [arg0]);
41
+ };
42
+
43
+ exports.consentReset = function (arg0, success, error) {
44
+ exec(success, error, 'emiAdmobPlugin', 'consentReset', [arg0]);
45
+ };
46
+
47
+ exports.targeting = function (arg0, arg1, arg2, success, error) {
48
+ exec(success, error, 'emiAdmobPlugin', 'targeting', [arg0, arg1, arg2]);
38
49
  };
@@ -1,59 +0,0 @@
1
- <html>
2
- <head>
3
- <script type="text/javascript" src="cordova.js"></script>
4
- </head>
5
- <body>
6
-
7
- <script>
8
-
9
-
10
- /// ( Must be Admob App-id-original. )
11
-
12
- /// The example here tries Interstitial ads.
13
-
14
- var interstitialAdAdUnitId = "Must be the original AdUnitId"
15
-
16
-
17
- function getMediationAdapterName() {
18
-
19
- cordova.plugins.emiAdmobPlugin.loadInterstitialAd(interstitialAdAdUnitId, success, error);
20
-
21
- function success(AdapterName){
22
-
23
- alert(AdapterName)
24
-
25
- }
26
-
27
- function error(e){
28
-
29
- alert(JSON.stringify(e))
30
-
31
- }
32
-
33
- };
34
-
35
-
36
- document.addEventListener("deviceready", function(){
37
-
38
- cordova.plugins.emiAdmobPlugin.initialize();
39
-
40
- // event Sdk initialize
41
-
42
- document.addEventListener('on.SdkInitializationComplete', () => {
43
-
44
- alert("get Mediation Adapter Name");
45
-
46
- getMediationAdapterName()
47
-
48
- });
49
-
50
- }, false);
51
-
52
-
53
- </script>
54
-
55
- <p> <button onclick="getMediationAdapterName();">get Mediation Adapter Name</button></p>
56
-
57
-
58
- </body>
59
- </html>