emi-indo-cordova-plugin-admob 1.4.0 → 1.4.1

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "emi-indo-cordova-plugin-admob",
3
- "version": "1.4.0",
4
- "description": "Cordova Plugin Admob Android",
3
+ "version": "1.4.1",
4
+ "description": "Cordova Plugin Admob Android IOS",
5
5
  "cordova": {
6
6
  "id": "emi-indo-cordova-plugin-admob",
7
7
  "platforms": [
@@ -18,10 +18,12 @@
18
18
  "cordova-admob-free",
19
19
  "cordova-admob-plus",
20
20
  "cordova-admob-pro",
21
- "construct 3"
21
+ "cordova-admob-ios",
22
+ "cordova-admob-android"
22
23
 
23
24
  ],
24
25
  "author": "EMI INDO",
26
+ "email": "cordova.c3addon@gmail.com",
25
27
  "license": "ISC",
26
28
  "repository": {
27
29
  "type": "git",
package/plugin.xml CHANGED
@@ -1,9 +1,9 @@
1
1
  <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
2
2
  xmlns:android="http://schemas.android.com/apk/res/android"
3
- id="emi-indo-cordova-plugin-admob" version="1.4.0">
3
+ id="emi-indo-cordova-plugin-admob" version="1.4.1">
4
4
 
5
5
  <name>emiAdmobPlugin</name>
6
- <description>Cordova Plugin Admob Android</description>
6
+ <description>Cordova Plugin Admob Android IOS</description>
7
7
  <author>EMI INDO</author>
8
8
  <license>ISC</license>
9
9
 
@@ -27,6 +27,11 @@
27
27
  </feature>
28
28
  </config-file>
29
29
 
30
+ <config-file parent="/*" target="AndroidManifest.xml">
31
+ <uses-permission android:name="android.permission.INTERNET" />
32
+ <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
33
+ </config-file>
34
+
30
35
 
31
36
  <config-file target="AndroidManifest.xml" parent="/manifest/application">
32
37
  <activity android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:excludeFromRecents="true" android:name="com.google.android.gms.ads.AdActivity" android:noHistory="true" />
@@ -66,7 +71,7 @@
66
71
  </feature>
67
72
  </config-file>
68
73
 
69
- <source-file src="src/ios/emiAdmobPlugin.swift" />
74
+ <preference name="USAGE" default="This identifier will be used to deliver personalized ads to you." />
70
75
 
71
76
  <preference name="APP_ID_IOS" default="ca-app-pub-3940256099942544~1458002511" />
72
77
 
@@ -74,9 +79,17 @@
74
79
  <string>$APP_ID_IOS</string>
75
80
  </config-file>
76
81
 
82
+ <config-file target="*-Info.plist" parent="NSUserTrackingUsageDescription">
83
+ <string>$USAGE</string>
84
+ </config-file>
85
+
86
+ <config-file target="*-Info.plist" parent="GADDelayAppMeasurementInit">
87
+ <true/>
88
+ </config-file>
89
+
77
90
  <config-file target="*-Info.plist" parent="SKAdNetworkItems">
78
91
  <array>
79
- <dict>
92
+ <dict>
80
93
  <key>SKAdNetworkIdentifier</key>
81
94
  <string>cstr6suwn9.skadnetwork</string>
82
95
  </dict>
@@ -118,19 +131,19 @@
118
131
  </dict>
119
132
  <dict>
120
133
  <key>SKAdNetworkIdentifier</key>
121
- <string>c6k4g5qg8m.skadnetwork</string>
134
+ <string>3sh42y64q3.skadnetwork</string>
122
135
  </dict>
123
136
  <dict>
124
137
  <key>SKAdNetworkIdentifier</key>
125
- <string>s39g8k73mm.skadnetwork</string>
138
+ <string>c6k4g5qg8m.skadnetwork</string>
126
139
  </dict>
127
140
  <dict>
128
141
  <key>SKAdNetworkIdentifier</key>
129
- <string>3qy4746246.skadnetwork</string>
142
+ <string>s39g8k73mm.skadnetwork</string>
130
143
  </dict>
131
144
  <dict>
132
145
  <key>SKAdNetworkIdentifier</key>
133
- <string>3sh42y64q3.skadnetwork</string>
146
+ <string>3qy4746246.skadnetwork</string>
134
147
  </dict>
135
148
  <dict>
136
149
  <key>SKAdNetworkIdentifier</key>
@@ -140,10 +153,6 @@
140
153
  <key>SKAdNetworkIdentifier</key>
141
154
  <string>hs6bdukanm.skadnetwork</string>
142
155
  </dict>
143
- <dict>
144
- <key>SKAdNetworkIdentifier</key>
145
- <string>prcb7njmu6.skadnetwork</string>
146
- </dict>
147
156
  <dict>
148
157
  <key>SKAdNetworkIdentifier</key>
149
158
  <string>v4nxqhlyqp.skadnetwork</string>
@@ -166,7 +175,11 @@
166
175
  </dict>
167
176
  <dict>
168
177
  <key>SKAdNetworkIdentifier</key>
169
- <string>9rd848q2bz.skadnetwork</string>
178
+ <string>gta9lk7p23.skadnetwork</string>
179
+ </dict>
180
+ <dict>
181
+ <key>SKAdNetworkIdentifier</key>
182
+ <string>vutu7akeur.skadnetwork</string>
170
183
  </dict>
171
184
  <dict>
172
185
  <key>SKAdNetworkIdentifier</key>
@@ -196,6 +209,10 @@
196
209
  <key>SKAdNetworkIdentifier</key>
197
210
  <string>9t245vhmpl.skadnetwork</string>
198
211
  </dict>
212
+ <dict>
213
+ <key>SKAdNetworkIdentifier</key>
214
+ <string>eh6m2bh4zr.skadnetwork</string>
215
+ </dict>
199
216
  <dict>
200
217
  <key>SKAdNetworkIdentifier</key>
201
218
  <string>a2p9lx4jpn.skadnetwork</string>
@@ -216,10 +233,6 @@
216
233
  <key>SKAdNetworkIdentifier</key>
217
234
  <string>8s468mfl3y.skadnetwork</string>
218
235
  </dict>
219
- <dict>
220
- <key>SKAdNetworkIdentifier</key>
221
- <string>av6w8kgt66.skadnetwork</string>
222
- </dict>
223
236
  <dict>
224
237
  <key>SKAdNetworkIdentifier</key>
225
238
  <string>klf5c3l5u5.skadnetwork</string>
@@ -230,15 +243,15 @@
230
243
  </dict>
231
244
  <dict>
232
245
  <key>SKAdNetworkIdentifier</key>
233
- <string>424m5254lk.skadnetwork</string>
246
+ <string>ecpz2srf59.skadnetwork</string>
234
247
  </dict>
235
248
  <dict>
236
249
  <key>SKAdNetworkIdentifier</key>
237
- <string>ecpz2srf59.skadnetwork</string>
250
+ <string>uw77j35x4d.skadnetwork</string>
238
251
  </dict>
239
252
  <dict>
240
253
  <key>SKAdNetworkIdentifier</key>
241
- <string>uw77j35x4d.skadnetwork</string>
254
+ <string>pwa73g5rt2.skadnetwork</string>
242
255
  </dict>
243
256
  <dict>
244
257
  <key>SKAdNetworkIdentifier</key>
@@ -252,10 +265,6 @@
252
265
  <key>SKAdNetworkIdentifier</key>
253
266
  <string>4dzt52r2t5.skadnetwork</string>
254
267
  </dict>
255
- <dict>
256
- <key>SKAdNetworkIdentifier</key>
257
- <string>gta9lk7p23.skadnetwork</string>
258
- </dict>
259
268
  <dict>
260
269
  <key>SKAdNetworkIdentifier</key>
261
270
  <string>e5fvkxwrpn.skadnetwork</string>
@@ -276,15 +285,21 @@
276
285
  <key>SKAdNetworkIdentifier</key>
277
286
  <string>3qcr597p9d.skadnetwork</string>
278
287
  </dict>
279
- </array>
288
+ </array>
280
289
  </config-file>
281
290
 
291
+ <header-file src="src/ios/emiAdmobPlugin.h" />
292
+ <source-file src="src/ios/emiAdmobPlugin.m" />
293
+
294
+ <framework src="AdSupport.framework" weak="true" />
295
+ <framework src="AppTrackingTransparency.framework" weak="true" />
296
+
282
297
  <podspec>
283
298
  <config>
284
299
  <source url="https://cdn.cocoapods.org/" />
285
300
  </config>
286
301
  <pods use-frameworks="true">
287
- <pod name="Google-Mobile-Ads-SDK" spec="~> 10.3.0" />
302
+ <pod name="Google-Mobile-Ads-SDK" spec="~> 10.13.0" />
288
303
  </pods>
289
304
  </podspec>
290
305
 
@@ -1 +1 @@
1
- package emi.indo.cordova.plugin.admob;import android.content.Context;import android.content.SharedPreferences;import android.os.Bundle;import android.util.Log;import android.view.View;import android.view.ViewGroup;import android.widget.RelativeLayout;import androidx.annotation.NonNull;import androidx.preference.PreferenceManager;import com.google.ads.mediation.admob.AdMobAdapter;import com.google.android.gms.ads.AdError;import com.google.android.gms.ads.AdListener;import com.google.android.gms.ads.AdRequest;import com.google.android.gms.ads.AdSize;import com.google.android.gms.ads.AdValue;import com.google.android.gms.ads.AdView;import com.google.android.gms.ads.FullScreenContentCallback;import com.google.android.gms.ads.LoadAdError;import com.google.android.gms.ads.MobileAds;import com.google.android.gms.ads.OnPaidEventListener;import com.google.android.gms.ads.RequestConfiguration;import com.google.android.gms.ads.ResponseInfo;import com.google.android.gms.ads.appopen.AppOpenAd;import com.google.android.gms.ads.initialization.AdapterStatus;import com.google.android.gms.ads.interstitial.InterstitialAd;import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback;import com.google.android.gms.ads.rewarded.RewardedAd;import com.google.android.gms.ads.rewarded.RewardedAdLoadCallback;import com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAd;import com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAdLoadCallback;import com.google.android.ump.ConsentForm;import com.google.android.ump.ConsentInformation;import com.google.android.ump.ConsentRequestParameters;import com.google.android.ump.UserMessagingPlatform;import org.apache.cordova.CallbackContext;import org.apache.cordova.CordovaInterface;import org.apache.cordova.CordovaPlugin;import org.apache.cordova.CordovaWebView;import org.json.JSONArray;import org.json.JSONException;import org.json.JSONObject;import java.util.Map;import java.util.Objects;public class emiAdmobPlugin extends CordovaPlugin{private static final String TAG="emiAdmobPlugin";private CallbackContext PUBLIC_CALLBACKS=null;private InterstitialAd mInterstitialAd;private RewardedAd rewardedAd;private RewardedInterstitialAd rewardedInterstitialAd;private CordovaWebView cWebView;private AppOpenAd appOpenAd=null;private boolean isAppOpenAdShow=false;private boolean isbannerShow=true;static boolean isinterstitialload=false;static boolean isrewardedInterstitialload=false;static boolean isrewardedload=false;static boolean isBannerLoad=false;String Npa;String Position;String Size;int AdaptiveWidth;Boolean ResponseInfo=false;int bannerAdImpression=0;private int isAdSkip=0;int SetTagForChildDirectedTreatment;int SetTagForUnderAgeOfConsent;String SetMaxAdContentRating;String appOpenAdUnitId;String bannerAdUnitId;String interstitialAdUnitId;String rewardedInterstitialAdUnitId;String rewardedAdUnitId;boolean SetAppMuted=true;float SetAppVolume;boolean EnableSameAppKey;private ConsentInformation consentInformation;private ConsentForm consentForm;private RelativeLayout bannerViewLayout;private AdView bannerView;public void initialize(CordovaInterface cordova,CordovaWebView webView){super.initialize(cordova,webView);cWebView=webView;}public boolean execute(String action,JSONArray args,final CallbackContext callbackContext)throws JSONException{PUBLIC_CALLBACKS=callbackContext;switch(action){case "initialize":Log.d(TAG,"Google Mobile Ads SDK: "+MobileAds.getVersion());_globalSettings();_Targeting();MobileAds.initialize(cordova.getContext(),initializationStatus ->{callbackContext.success(" Google Mobile Ads SDK: "+MobileAds.getVersion());Map<String,AdapterStatus> statusMap=initializationStatus.getAdapterStatusMap();for(String adapterClass:statusMap.keySet()){AdapterStatus status=statusMap.get(adapterClass);if(status!=null){Log.d(TAG,String.format("Adapter name:%s,Description:%s,Latency:%d",adapterClass,status.getDescription(),status.getLatency()));}else{callbackContext.error(MobileAds.ERROR_DOMAIN);}}cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.sdkInitialization');");});return true;case "targeting":cordova.getActivity().runOnUiThread(()->{final int TagForChildDirectedTreatment=args.optInt(0);final int TagForUnderAgeOfConsent=args.optInt(1);final String MaxAdContentRating=args.optString(2);try{this.SetTagForChildDirectedTreatment=TagForChildDirectedTreatment;this.SetTagForUnderAgeOfConsent=TagForUnderAgeOfConsent;this.SetMaxAdContentRating=MaxAdContentRating;}catch(Exception e){callbackContext.error(e.toString());}});return true;case "globalSettings":cordova.getActivity().runOnUiThread(()->{final boolean setAppMuted=args.optBoolean(0);final float setAppVolume=(float)args.optDouble(1);final boolean enableSameAppKey=args.optBoolean(2);try{this.SetAppMuted=setAppMuted;this.SetAppVolume=setAppVolume;this.EnableSameAppKey=enableSameAppKey;}catch(Exception e){callbackContext.error(e.toString());}});return true;case "loadAppOpenAd":cordova.getActivity().runOnUiThread(()->{final String adUnitId=args.optString(0);final String npa=args.optString(1);final boolean responseInfo=args.optBoolean(2);try{this.appOpenAdUnitId=adUnitId;Bundle bundleExtra=new Bundle();bundleExtra.putString("npa",npa);bundleExtra.putInt("is_designed_for_families",this.SetTagForChildDirectedTreatment);bundleExtra.putInt("under_age_of_consent",this.SetTagForUnderAgeOfConsent);bundleExtra.putString("max_ad_content_rating",this.SetMaxAdContentRating);AdRequest adRequest=new AdRequest.Builder().addNetworkExtrasBundle(AdMobAdapter.class,bundleExtra).build();AppOpenAd.load(cordova.getContext(),this.appOpenAdUnitId,adRequest,new AppOpenAd.AppOpenAdLoadCallback(){@Override public void onAdLoaded(@NonNull AppOpenAd ad){appOpenAd=ad;isAppOpenAdShow=true;appOpenAd.setOnPaidEventListener(adValue ->{long valueMicros=adValue.getValueMicros();String currencyCode=adValue.getCurrencyCode();int precision=adValue.getPrecisionType();String adUnitId=appOpenAd.getAdUnitId();JSONObject result=new JSONObject();try{result.put("micros",valueMicros);result.put("currency",currencyCode);result.put("precision",precision);result.put("adUnitId",adUnitId);callbackContext.success(result);cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.appOpenAd.revenue');");}catch(JSONException e){callbackContext.error(e.getMessage());}});cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.appOpenAd.loaded');");if(responseInfo){ResponseInfo responseInfo=appOpenAd.getResponseInfo();callbackContext.success(responseInfo.toString()+ '\n'+'\n'+bundleExtra);}}@Override public void onAdFailedToLoad(@NonNull LoadAdError loadAdError){isAppOpenAdShow=false;callbackContext.error(loadAdError.toString());cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.appOpenAd.failed.loaded');");}});}catch(Exception e){callbackContext.error(e.toString());}});return true;case "showAppOpenAd":if(isAppOpenAdShow){_appOpenAdLoadCallback(callbackContext);cordova.getActivity().runOnUiThread(()-> appOpenAd.show(cordova.getActivity()));}else{callbackContext.error("The App Open Ad wasn't ready yet");}return true;case "loadInterstitialAd":cordova.getActivity().runOnUiThread(()->{final String adUnitId=args.optString(0);final String npa=args.optString(1);final boolean responseInfo=args.optBoolean(2);try{this.interstitialAdUnitId=adUnitId;Bundle bundleExtra=new Bundle();bundleExtra.putString("npa",npa);bundleExtra.putInt("is_designed_for_families",this.SetTagForChildDirectedTreatment);bundleExtra.putInt("under_age_of_consent",this.SetTagForUnderAgeOfConsent);bundleExtra.putString("max_ad_content_rating",this.SetMaxAdContentRating);AdRequest adRequest=new AdRequest.Builder().addNetworkExtrasBundle(AdMobAdapter.class,bundleExtra).build();InterstitialAd.load(cordova.getActivity(),this.interstitialAdUnitId,adRequest,new InterstitialAdLoadCallback(){@Override public void onAdLoaded(@NonNull InterstitialAd interstitialAd){isinterstitialload=true;mInterstitialAd=interstitialAd;Log.i(TAG,"onAdLoaded");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.interstitial.loaded');");if(responseInfo){ResponseInfo responseInfo=interstitialAd.getResponseInfo();callbackContext.success(responseInfo.toString()+ '\n'+'\n'+bundleExtra);}mInterstitialAd.setOnPaidEventListener(adValue ->{long valueMicros=adValue.getValueMicros();String currencyCode=adValue.getCurrencyCode();int precision=adValue.getPrecisionType();String adUnitId=mInterstitialAd.getAdUnitId();JSONObject result=new JSONObject();try{result.put("micros",valueMicros);result.put("currency",currencyCode);result.put("precision",precision);result.put("adUnitId",adUnitId);callbackContext.success(result);}catch(JSONException e){callbackContext.error(e.getMessage());}cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.interstitial.revenue');");});}@Override public void onAdFailedToLoad(@NonNull LoadAdError loadAdError){mInterstitialAd=null;isinterstitialload=false;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.interstitial.failed.load');");callbackContext.error(loadAdError.toString());}});}catch(Exception e){callbackContext.error(e.toString());}});return true;case "showInterstitialAd":if(isinterstitialload){_interstitialAdLoadCallback(callbackContext);cordova.getActivity().runOnUiThread(()-> mInterstitialAd.show(cordova.getActivity()));}else{callbackContext.error("The Interstitial ad wasn't ready yet");}return true;case "loadRewardedAd":cordova.getActivity().runOnUiThread(()->{final String adUnitId=args.optString(0);final String npa=args.optString(1);final boolean responseInfo=args.optBoolean(2);try{this.rewardedAdUnitId=adUnitId;Bundle bundleExtra=new Bundle();bundleExtra.putString("npa",npa);bundleExtra.putInt("is_designed_for_families",this.SetTagForChildDirectedTreatment);bundleExtra.putInt("under_age_of_consent",this.SetTagForUnderAgeOfConsent);bundleExtra.putString("max_ad_content_rating",this.SetMaxAdContentRating);AdRequest adRequest=new AdRequest.Builder().addNetworkExtrasBundle(AdMobAdapter.class,bundleExtra).build();RewardedAd.load(cordova.getActivity(),this.rewardedAdUnitId,adRequest,new RewardedAdLoadCallback(){public void onAdFailedToLoad(@NonNull LoadAdError loadAdError){rewardedAd=null;isrewardedload=false;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewarded.failed.load');");callbackContext.error(loadAdError.toString());}@Override public void onAdLoaded(@NonNull RewardedAd ad){rewardedAd=ad;isrewardedload=true;isAdSkip=0;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewarded.loaded');");if(responseInfo){ResponseInfo responseInfo=ad.getResponseInfo();callbackContext.success(responseInfo.toString()+ '\n'+'\n'+bundleExtra);}rewardedAd.setOnPaidEventListener(adValue ->{long valueMicros=adValue.getValueMicros();String currencyCode=adValue.getCurrencyCode();int precision=adValue.getPrecisionType();String adUnitId=rewardedAd.getAdUnitId();JSONObject result=new JSONObject();try{result.put("micros",valueMicros);result.put("currency",currencyCode);result.put("precision",precision);result.put("adUnitId",adUnitId);callbackContext.success(result);}catch(JSONException e){callbackContext.error(e.getMessage());}cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewarded.revenue');");});}});}catch(Exception e){callbackContext.error(e.toString());}});return true;case "showRewardedAd":cordova.getActivity().runOnUiThread(()->{if(isrewardedload){isAdSkip=1;_rewardedAdLoadCallback(callbackContext);rewardedAd.show(cordova.getActivity(),rewardItem ->{isAdSkip=2;int rewardAmount=rewardItem.getAmount();String rewardType=rewardItem.getType();cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.reward.userEarnedReward');");callbackContext.success("rewardAmount:"+rewardAmount+"rewardType:"+rewardType);});}else{callbackContext.error("The rewarded ad wasn't ready yet");}});return true;case "loadRewardedInterstitialAd":cordova.getActivity().runOnUiThread(()->{final String adUnitId=args.optString(0);final String npa=args.optString(1);final boolean responseInfo=args.optBoolean(2);try{this.rewardedInterstitialAdUnitId=adUnitId;Bundle bundleExtra=new Bundle();bundleExtra.putString("npa",npa);bundleExtra.putInt("is_designed_for_families",this.SetTagForChildDirectedTreatment);bundleExtra.putInt("under_age_of_consent",this.SetTagForUnderAgeOfConsent);bundleExtra.putString("max_ad_content_rating",this.SetMaxAdContentRating);AdRequest adRequest=new AdRequest.Builder().addNetworkExtrasBundle(AdMobAdapter.class,bundleExtra).build();RewardedInterstitialAd.load(cordova.getActivity(),this.rewardedInterstitialAdUnitId,adRequest,new RewardedInterstitialAdLoadCallback(){@Override public void onAdLoaded(@NonNull RewardedInterstitialAd ad){rewardedInterstitialAd=ad;isrewardedInterstitialload=true;isAdSkip=0;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInt.loaded');");if(responseInfo){ResponseInfo responseInfo=ad.getResponseInfo();callbackContext.success(responseInfo.toString()+ '\n'+'\n'+bundleExtra);}rewardedInterstitialAd.setOnPaidEventListener(adValue ->{long valueMicros=adValue.getValueMicros();String currencyCode=adValue.getCurrencyCode();int precision=adValue.getPrecisionType();String adUnitId=rewardedInterstitialAd.getAdUnitId();JSONObject result=new JSONObject();try{result.put("micros",valueMicros);result.put("currency",currencyCode);result.put("precision",precision);result.put("adUnitId",adUnitId);callbackContext.success(result);}catch(JSONException e){callbackContext.error(e.getMessage());}cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInt.revenue');");});}@Override public void onAdFailedToLoad(@NonNull LoadAdError loadAdError){rewardedInterstitialAd=null;isrewardedInterstitialload=false;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInt.failed.load');");callbackContext.error(loadAdError.toString());}});}catch(Exception e){callbackContext.error(e.toString());}});return true;case "showRewardedInterstitialAd":cordova.getActivity().runOnUiThread(()->{if(isrewardedInterstitialload){isAdSkip=1;_rewardedInterstitialAdLoadCallback(callbackContext);rewardedInterstitialAd.show(cordova.getActivity(),rewardItem ->{isAdSkip=2;int rewardAmount=rewardItem.getAmount();String rewardType=rewardItem.getType();cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInt.userEarnedReward');");callbackContext.success("rewardAmount:"+rewardAmount+"rewardType:"+rewardType);});}else{callbackContext.error("The rewarded ad wasn't ready yet");}});return true;case "showBannerAd":cordova.getActivity().runOnUiThread(()->{if(isBannerLoad){bannerViewLayout.addView(bannerView);isBannerLoad=false;}});return true;case "loadBannerAd":cordova.getActivity().runOnUiThread(()->{final String adUnitId=args.optString(0);final String npa=args.optString(1);final String position=args.optString(2);final String size=args.optString(3);final int adaptiveWidth=args.optInt(4);final boolean responseInfo=args.optBoolean(5);try{this.bannerAdUnitId=adUnitId;this.Npa=npa;this.Position=position;this.Size=size;this.AdaptiveWidth=adaptiveWidth;this.ResponseInfo=responseInfo;_loadBannerAd(bannerAdUnitId,Npa,Position,Size,AdaptiveWidth);}catch(Exception e){callbackContext.error(e.toString());}});return true;case "removeBannerAd":cordova.getActivity().runOnUiThread(()->{if(bannerView==null)return;RelativeLayout bannerViewLayout=(RelativeLayout)bannerView.getParent();if(bannerViewLayout!=null){bannerViewLayout.removeView(bannerView);bannerView.destroy();bannerView=null;isbannerShow=true;bannerAdImpression=0;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.banner.remove');");}});return true;case "getConsentRequest":cordova.getActivity().runOnUiThread(()->{try{ConsentRequestParameters params=new ConsentRequestParameters .Builder().build();consentInformation=UserMessagingPlatform.getConsentInformation(cordova.getContext());consentInformation.requestConsentInfoUpdate(cordova.getActivity(),params,()->{cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.info.update');");if(consentInformation.getConsentStatus()==ConsentInformation.ConsentStatus.NOT_REQUIRED){callbackContext.success(ConsentInformation.ConsentStatus.NOT_REQUIRED);cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.status.not_required');");}else if(consentInformation.getConsentStatus()==ConsentInformation.ConsentStatus.OBTAINED){callbackContext.success(ConsentInformation.ConsentStatus.OBTAINED);cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.status.obtained');");}else if(consentInformation.getConsentStatus()==ConsentInformation.ConsentStatus.REQUIRED){callbackContext.success(ConsentInformation.ConsentStatus.REQUIRED);cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.status.required');");if(consentInformation.isConsentFormAvailable()){UserMessagingPlatform.loadConsentForm(cordova.getContext(),consentForm -> consentForm.show(cordova.getActivity(),formError ->{cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.failed.show');");callbackContext.error(String.valueOf(formError));}),formError -> callbackContext.error(formError.getMessage()));cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.failed.load.from');");}else{cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.form.not.available');");}}else if(consentInformation.getConsentStatus()==ConsentInformation.ConsentStatus.UNKNOWN){callbackContext.success(ConsentInformation.ConsentStatus.UNKNOWN);cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.status.unknown');");}},formError ->{cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.info.update.failed');");callbackContext.error(formError.getMessage());});}catch(Exception e){callbackContext.error(e.toString());}});return true;case "showPrivacyOptionsForm":cordova.getActivity().runOnUiThread(this::consentInfoUpdate);return true;case "consentReset":cordova.getActivity().runOnUiThread(()->{if(consentInformation!=null){consentInformation.reset();}});return true;case "getIabTfc":cordova.getActivity().runOnUiThread(()->{Context context=this.cordova.getActivity().getApplicationContext();SharedPreferences mPreferences=PreferenceManager.getDefaultSharedPreferences(context);int gdprApplies=mPreferences.getInt("IABTCF_gdprApplies",0);String consentString=mPreferences.getString("IABTCF_TCString","");String purposeConsents=mPreferences.getString("IABTCF_PurposeConsents","");JSONObject userInfoJson=new JSONObject();try{userInfoJson.put("IABTCF_TCString",consentString);userInfoJson.put("IABTCF_PurposeConsents",purposeConsents);userInfoJson.put("IABTCF_gdprApplies",gdprApplies);callbackContext.success(userInfoJson);cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.getIabTfc');");}catch(Exception e){callbackContext.error(e.toString());cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.getIabTfc.error');");}});return true;}return false;}public boolean isPrivacyOptionsRequired(){return consentInformation.getPrivacyOptionsRequirementStatus()==ConsentInformation.PrivacyOptionsRequirementStatus.REQUIRED;}private void consentInfoUpdate(){ConsentRequestParameters params=new ConsentRequestParameters .Builder().setTagForUnderAgeOfConsent(false).build();consentInformation=UserMessagingPlatform.getConsentInformation(cordova.getContext());consentInformation.requestConsentInfoUpdate(cordova.getActivity(),params,(ConsentInformation.OnConsentInfoUpdateSuccessListener)this::OptionsMenu,(ConsentInformation.OnConsentInfoUpdateFailureListener)requestConsentError ->{PUBLIC_CALLBACKS.error(requestConsentError.getMessage());});}private void OptionsMenu(){try{UserMessagingPlatform.loadAndShowConsentFormIfRequired(cordova.getActivity(),(ConsentForm.OnConsentFormDismissedListener)loadAndShowError ->{if(loadAndShowError!=null){PUBLIC_CALLBACKS.error(loadAndShowError.getMessage());}if(isPrivacyOptionsRequired()){invalidateOptionsMenu();}});}catch(Exception e){throw new RuntimeException(e);}}private void invalidateOptionsMenu(){UserMessagingPlatform.showPrivacyOptionsForm(cordova.getActivity(),formError ->{if(formError!=null){PUBLIC_CALLBACKS.error(formError.getMessage());}});}private void _loadBannerAd(String bannerAdUnitId,String Npa,String Position,String Size,int AdaptiveWidth){if(isbannerShow){if(bannerViewLayout==null){bannerViewLayout=new RelativeLayout(cordova.getActivity());RelativeLayout.LayoutParams params=new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.WRAP_CONTENT);bannerViewLayout.setLayoutParams(params);try{((ViewGroup)(((View)Objects.requireNonNull(webView.getClass().getMethod("getView").invoke(webView))).getParent())).addView(bannerViewLayout,params);}catch(Exception e){((ViewGroup)webView).addView(bannerViewLayout,params);}}bannerView=new AdView(cordova.getActivity());if(Objects.equals(Size,"BANNER")){bannerView.setAdSize(AdSize.BANNER);}else if(Objects.equals(Size,"LARGE_BANNER")){bannerView.setAdSize(AdSize.LARGE_BANNER);}else if(Objects.equals(Size,"MEDIUM_RECTANGLE")){bannerView.setAdSize(AdSize.MEDIUM_RECTANGLE);}else if(Objects.equals(Size,"FULL_BANNER")){bannerView.setAdSize(AdSize.FULL_BANNER);}else if(Objects.equals(Size,"LEADERBOARD")){bannerView.setAdSize(AdSize.LEADERBOARD);}else if(Objects.equals(Size,"FLUID")){bannerView.setAdSize(AdSize.FLUID);}else if(Objects.equals(Size,"Anchored_adaptive")){bannerView.setAdSize(AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(cordova.getActivity(),AdaptiveWidth));}else if(Objects.equals(Size,"Inline_adaptive")){bannerView.setAdSize(AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize(cordova.getActivity(),AdaptiveWidth));}else if(Objects.equals(Size,"FULL_WIDTH")){bannerView.setAdSize(AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize(cordova.getActivity(),AdSize.FULL_WIDTH));}else{bannerView.setAdSize(AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(cordova.getActivity(),AdSize.FULL_WIDTH));}bannerView.setAdUnitId(bannerAdUnitId);Bundle bundleExtra=new Bundle();bundleExtra.putString("npa",Npa);bundleExtra.putInt("is_designed_for_families",this.SetTagForChildDirectedTreatment);bundleExtra.putInt("under_age_of_consent",this.SetTagForUnderAgeOfConsent);bundleExtra.putString("max_ad_content_rating",this.SetMaxAdContentRating);AdRequest adRequest=new AdRequest.Builder().addNetworkExtrasBundle(AdMobAdapter.class,bundleExtra).build();bannerView.loadAd(adRequest);bannerView.setAdListener(bannerAdListener);isbannerShow=false;RelativeLayout.LayoutParams bannerParams=new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);switch(Position){case "top-right":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);bannerParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);break;case "top-center":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);bannerParams.addRule(RelativeLayout.CENTER_HORIZONTAL);break;case "left":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);bannerParams.addRule(RelativeLayout.CENTER_VERTICAL);break;case "center":bannerParams.addRule(RelativeLayout.CENTER_HORIZONTAL);bannerParams.addRule(RelativeLayout.CENTER_VERTICAL);break;case "right":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);bannerParams.addRule(RelativeLayout.CENTER_VERTICAL);break;case "bottom-center":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);bannerParams.addRule(RelativeLayout.CENTER_HORIZONTAL);break;case "bottom-right":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);bannerParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);break;default:bannerParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);bannerParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);break;}bannerView.setLayoutParams(bannerParams);}}private final AdListener bannerAdListener=new AdListener(){@Override public void onAdClicked(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.banner.click');");}@Override public void onAdClosed(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.banner.close');");}@Override public void onAdFailedToLoad(@NonNull LoadAdError adError){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.banner.failed.load');");PUBLIC_CALLBACKS.error(adError.toString());}@Override public void onAdImpression(){isbannerShow=false;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.banner.impression');");}@Override public void onAdLoaded(){if(bannerAdImpression==0){isBannerLoad=true;}isbannerShow=false;bannerAdImpression=1;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.banner.load');");bannerView.setOnPaidEventListener(bannerPaidAdListener);if(ResponseInfo){Bundle bundleExtra=new Bundle();bundleExtra.putString("npa",Npa);bundleExtra.putInt("is_designed_for_families",SetTagForChildDirectedTreatment);bundleExtra.putInt("under_age_of_consent",SetTagForUnderAgeOfConsent);bundleExtra.putString("max_ad_content_rating",SetMaxAdContentRating);try{ResponseInfo responseInfo=bannerView.getResponseInfo();assert responseInfo!=null;PUBLIC_CALLBACKS.success(responseInfo.toString()+ '\n'+'\n'+bundleExtra);}catch(NullPointerException e){e.printStackTrace();}}}@Override public void onAdOpened(){isbannerShow=false;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.banner.open');");}};private final OnPaidEventListener bannerPaidAdListener=new OnPaidEventListener(){@Override public void onPaidEvent(@NonNull AdValue adValue){long valueMicros=adValue.getValueMicros();String currencyCode=adValue.getCurrencyCode();int precision=adValue.getPrecisionType();String adUnitId=bannerView.getAdUnitId();JSONObject result=new JSONObject();try{result.put("micros",valueMicros);result.put("currency",currencyCode);result.put("precision",precision);result.put("adUnitId",adUnitId);PUBLIC_CALLBACKS.success(result);cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.banner.revenue');");}catch(JSONException e){PUBLIC_CALLBACKS.error(e.getMessage());}}};private void _appOpenAdLoadCallback(CallbackContext callbackContext){appOpenAd.setFullScreenContentCallback(new FullScreenContentCallback(){@Override public void onAdDismissedFullScreenContent(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.appOpenAd.dismissed');");appOpenAd=null;}@Override public void onAdFailedToShowFullScreenContent(@NonNull AdError adError){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.appOpenAd.failed.show');");callbackContext.error(adError.toString());appOpenAd=null;}@Override public void onAdShowedFullScreenContent(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.appOpenAd.show');");}});}private void _interstitialAdLoadCallback(CallbackContext callbackContext){mInterstitialAd.setFullScreenContentCallback(new FullScreenContentCallback(){@Override public void onAdClicked(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.interstitial.click');");}@Override public void onAdDismissedFullScreenContent(){mInterstitialAd=null;isinterstitialload=false;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.interstitial.dismissed');");}@Override public void onAdFailedToShowFullScreenContent(@NonNull AdError adError){mInterstitialAd=null;isinterstitialload=false;callbackContext.error(adError.toString());cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.interstitial.failed.show');");}@Override public void onAdImpression(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.interstitial.impression');");}@Override public void onAdShowedFullScreenContent(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.interstitial.show');");}});}private void _rewardedAdLoadCallback(CallbackContext callbackContext){rewardedAd.setFullScreenContentCallback(new FullScreenContentCallback(){@Override public void onAdClicked(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewarded.click');");}@Override public void onAdDismissedFullScreenContent(){if(isAdSkip!=2){rewardedAd=null;isrewardedload=false;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewarded.ad.skip');");}rewardedAd=null;isrewardedload=false;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewarded.dismissed');");}@Override public void onAdFailedToShowFullScreenContent(@NonNull AdError adError){rewardedAd=null;isrewardedload=false;callbackContext.error(adError.toString());cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewarded.failed.show');");}@Override public void onAdImpression(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewarded.impression');");}@Override public void onAdShowedFullScreenContent(){isAdSkip=1;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewarded.show');");}});}private void _rewardedInterstitialAdLoadCallback(CallbackContext callbackContext){rewardedInterstitialAd.setFullScreenContentCallback(new FullScreenContentCallback(){@Override public void onAdClicked(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInt.click');");}@Override public void onAdDismissedFullScreenContent(){if(isAdSkip!=2){rewardedInterstitialAd=null;isrewardedInterstitialload=false;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInt.ad.skip');");}rewardedInterstitialAd=null;isrewardedInterstitialload=false;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInt.dismissed');");}@Override public void onAdFailedToShowFullScreenContent(@NonNull AdError adError){rewardedInterstitialAd=null;isrewardedInterstitialload=false;callbackContext.error(adError.toString());cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInt.failed.show');");}@Override public void onAdImpression(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInt.impression');");}@Override public void onAdShowedFullScreenContent(){isAdSkip=1;Log.d(TAG,"Ad showed fullscreen content.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInt.showed');");}});}public void _globalSettings(){MobileAds.setAppMuted(this.SetAppMuted);MobileAds.setAppVolume(this.SetAppVolume);MobileAds.enableSameAppKey(this.EnableSameAppKey);}public void _Targeting(){RequestConfiguration.Builder requestConfiguration=MobileAds.getRequestConfiguration().toBuilder();if(SetTagForChildDirectedTreatment==-1){requestConfiguration.setTagForChildDirectedTreatment(RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_UNSPECIFIED);}else if(SetTagForChildDirectedTreatment==0){requestConfiguration.setTagForChildDirectedTreatment(RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_FALSE);}else if(SetTagForChildDirectedTreatment==1){requestConfiguration.setTagForChildDirectedTreatment(RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_TRUE);}else{requestConfiguration.setTagForChildDirectedTreatment(RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_UNSPECIFIED);}if(SetTagForUnderAgeOfConsent==-1){requestConfiguration.setTagForUnderAgeOfConsent(RequestConfiguration.TAG_FOR_UNDER_AGE_OF_CONSENT_UNSPECIFIED);}else if(SetTagForUnderAgeOfConsent==0){requestConfiguration.setTagForUnderAgeOfConsent(RequestConfiguration.TAG_FOR_UNDER_AGE_OF_CONSENT_FALSE);}else if(SetTagForUnderAgeOfConsent==1){requestConfiguration.setTagForUnderAgeOfConsent(RequestConfiguration.TAG_FOR_UNDER_AGE_OF_CONSENT_TRUE);}else{requestConfiguration.setTagForUnderAgeOfConsent(RequestConfiguration.TAG_FOR_UNDER_AGE_OF_CONSENT_UNSPECIFIED);}if(Objects.equals(SetMaxAdContentRating,"")){requestConfiguration.setMaxAdContentRating(RequestConfiguration.MAX_AD_CONTENT_RATING_UNSPECIFIED);}else if(Objects.equals(SetMaxAdContentRating,"T")){requestConfiguration.setMaxAdContentRating(RequestConfiguration.MAX_AD_CONTENT_RATING_T);}else if(Objects.equals(SetMaxAdContentRating,"PG")){requestConfiguration.setMaxAdContentRating(RequestConfiguration.MAX_AD_CONTENT_RATING_PG);}else if(Objects.equals(SetMaxAdContentRating,"MA")){requestConfiguration.setMaxAdContentRating(RequestConfiguration.MAX_AD_CONTENT_RATING_MA);}else if(Objects.equals(SetMaxAdContentRating,"G")){requestConfiguration.setMaxAdContentRating(RequestConfiguration.MAX_AD_CONTENT_RATING_G);}else{requestConfiguration.setTagForUnderAgeOfConsent(RequestConfiguration.TAG_FOR_UNDER_AGE_OF_CONSENT_UNSPECIFIED);}MobileAds.setRequestConfiguration(requestConfiguration.build());}@Override public void onPause(boolean multitasking){if(bannerView!=null){bannerView.pause();}super.onPause(multitasking);}@Override public void onResume(boolean multitasking){super.onResume(multitasking);if(bannerView!=null){bannerView.resume();}}@Override public void onDestroy(){if(bannerView!=null){bannerView.destroy();bannerView=null;}if(bannerViewLayout!=null){ViewGroup parentView=(ViewGroup)bannerViewLayout.getParent();if(parentView!=null){parentView.removeView(bannerViewLayout);}bannerViewLayout=null;}isbannerShow=true;bannerAdImpression=0;super.onDestroy();}}
1
+ package emi.indo.cordova.plugin.admob;import android.app.Activity;import android.content.Context;import android.content.SharedPreferences;import android.content.res.Configuration;import android.os.Bundle;import android.util.Log;import android.view.View;import android.view.ViewGroup;import android.widget.RelativeLayout;import androidx.annotation.NonNull;import androidx.preference.PreferenceManager;import com.google.ads.mediation.admob.AdMobAdapter;import com.google.android.gms.ads.AdError;import com.google.android.gms.ads.AdListener;import com.google.android.gms.ads.AdRequest;import com.google.android.gms.ads.AdSize;import com.google.android.gms.ads.AdValue;import com.google.android.gms.ads.AdView;import com.google.android.gms.ads.FullScreenContentCallback;import com.google.android.gms.ads.LoadAdError;import com.google.android.gms.ads.MobileAds;import com.google.android.gms.ads.OnPaidEventListener;import com.google.android.gms.ads.RequestConfiguration;import com.google.android.gms.ads.ResponseInfo;import com.google.android.gms.ads.appopen.AppOpenAd;import com.google.android.gms.ads.initialization.AdapterStatus;import com.google.android.gms.ads.interstitial.InterstitialAd;import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback;import com.google.android.gms.ads.rewarded.RewardedAd;import com.google.android.gms.ads.rewarded.RewardedAdLoadCallback;import com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAd;import com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAdLoadCallback;import com.google.android.ump.ConsentForm;import com.google.android.ump.ConsentInformation;import com.google.android.ump.ConsentRequestParameters;import com.google.android.ump.UserMessagingPlatform;import org.apache.cordova.CallbackContext;import org.apache.cordova.CordovaInterface;import org.apache.cordova.CordovaPlugin;import org.apache.cordova.CordovaWebView;import org.json.JSONArray;import org.json.JSONException;import org.json.JSONObject;import java.util.Map;import java.util.Objects;public class emiAdmobPlugin extends CordovaPlugin{private static final String TAG="emiAdmobPlugin";private CallbackContext PUBLIC_CALLBACKS=null;private InterstitialAd mInterstitialAd;private RewardedAd rewardedAd;private RewardedInterstitialAd rewardedInterstitialAd;private CordovaWebView cWebView;private boolean isAppOpenAdShow=false;static boolean isinterstitialload=false;static boolean isrewardedInterstitialload=false;static boolean isrewardedload=false;int isBannerPause=0;String Npa;String Position;String Size;int AdaptiveWidth=320;Boolean ResponseInfo=false;int bannerAdImpression=0;private int isAdSkip=0;int SetTagForChildDirectedTreatment=-1;int SetTagForUnderAgeOfConsent=-1;String SetMaxAdContentRating="G";String appOpenAdUnitId;String bannerAdUnitId;String interstitialAdUnitId;String rewardedInterstitialAdUnitId;String rewardedAdUnitId;boolean SetAppMuted=false;float SetAppVolume=1;boolean EnableSameAppKey=false;private ConsentInformation consentInformation;private RelativeLayout bannerViewLayout;private AdView bannerView;private boolean isBannerLoad=false;private boolean isBannerShow=false;Boolean bannerAutoShow=false;Boolean appOpenAutoShow=false;Boolean intAutoShow=false;Boolean rewardedAutoShow=false;Boolean rIntAutoShow=false;String Collapsible;Boolean isCollapsible=false;Boolean lock=true;protected Activity mActivity;protected Context mContext;private AppOpenAd appOpenAd;int orientation=0;public void initialize(CordovaInterface cordova,CordovaWebView webView){super.initialize(cordova,webView);cWebView=webView;mActivity=this.cordova.getActivity();mContext=mActivity.getApplicationContext();int orientation=mActivity.getResources().getConfiguration().orientation;if(orientation==Configuration.ORIENTATION_PORTRAIT){this.orientation=0;}else{this.orientation=1;}}public boolean execute(String action,JSONArray args,final CallbackContext callbackContext)throws JSONException{PUBLIC_CALLBACKS=callbackContext;switch(action){case "initialize":Log.d(TAG,"Google Mobile Ads SDK: "+MobileAds.getVersion());MobileAds.initialize(mContext,initializationStatus ->{Map<String,AdapterStatus> statusMap=initializationStatus.getAdapterStatusMap();for(String adapterClass:statusMap.keySet()){AdapterStatus status=statusMap.get(adapterClass);if(status!=null){Log.d(TAG,String.format("Adapter name:%s,Description:%s,Latency:%d",adapterClass,status.getDescription(),status.getLatency()));}else{callbackContext.error(MobileAds.ERROR_DOMAIN);}}callbackContext.success("Google Mobile Ads SDK: "+MobileAds.getVersion());cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.sdkInitialization');");});return true;case "targeting":cordova.getActivity().runOnUiThread(()->{final int TagForChildDirectedTreatment=args.optInt(0);final int TagForUnderAgeOfConsent=args.optInt(1);final String MaxAdContentRating=args.optString(2);try{this.SetTagForChildDirectedTreatment=TagForChildDirectedTreatment;this.SetTagForUnderAgeOfConsent=TagForUnderAgeOfConsent;this.SetMaxAdContentRating=MaxAdContentRating;_Targeting();}catch(Exception e){callbackContext.error(e.toString());}});return true;case "globalSettings":cordova.getActivity().runOnUiThread(()->{final boolean setAppMuted=args.optBoolean(0);final float setAppVolume=(float)args.optDouble(1);final boolean enableSameAppKey=args.optBoolean(2);final String npa=args.optString(3);final boolean enableCollapsible=args.optBoolean(4);final boolean responseInfo=args.optBoolean(5);try{this.SetAppMuted=setAppMuted;this.SetAppVolume=setAppVolume;this.EnableSameAppKey=enableSameAppKey;this.Npa=npa;this.isCollapsible=enableCollapsible;this.ResponseInfo=responseInfo;_globalSettings();}catch(Exception e){callbackContext.error(e.toString());}});return true;case "loadAppOpenAd":cordova.getActivity().runOnUiThread(()->{final String adUnitId=args.optString(0);final boolean autoShow=args.optBoolean(1);try{this.appOpenAdUnitId=adUnitId;this.appOpenAutoShow=autoShow;Bundle bundleExtra=new Bundle();bundleExtra.putString("npa",this.Npa);bundleExtra.putInt("is_designed_for_families",this.SetTagForChildDirectedTreatment);bundleExtra.putInt("under_age_of_consent",this.SetTagForUnderAgeOfConsent);bundleExtra.putString("max_ad_content_rating",this.SetMaxAdContentRating);AdRequest adRequest=new AdRequest.Builder().addNetworkExtrasBundle(AdMobAdapter.class,bundleExtra).build();AppOpenAd.load(mActivity,this.appOpenAdUnitId,adRequest,new AppOpenAd.AppOpenAdLoadCallback(){@Override public void onAdLoaded(@NonNull AppOpenAd ad){appOpenAd=ad;isAppOpenAdShow=true;if(appOpenAutoShow){cordova.getActivity().runOnUiThread(()-> appOpenAd.show(mActivity));_appOpenAdLoadCallback(callbackContext);}appOpenAd.setOnPaidEventListener(adValue ->{long valueMicros=adValue.getValueMicros();String currencyCode=adValue.getCurrencyCode();int precision=adValue.getPrecisionType();String adUnitId=appOpenAd.getAdUnitId();JSONObject result=new JSONObject();try{result.put("micros",valueMicros);result.put("currency",currencyCode);result.put("precision",precision);result.put("adUnitId",adUnitId);callbackContext.success(result);cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.appOpenAd.revenue');");}catch(JSONException e){callbackContext.error(e.getMessage());}});cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.appOpenAd.loaded');");if(ResponseInfo){ResponseInfo responseInfo=appOpenAd.getResponseInfo();callbackContext.success(responseInfo.toString()+ '\n'+'\n'+bundleExtra);}}@Override public void onAdFailedToLoad(@NonNull LoadAdError loadAdError){isAppOpenAdShow=false;callbackContext.error(loadAdError.toString());cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.appOpenAd.failed.loaded');");}});}catch(Exception e){callbackContext.error(e.toString());}});return true;case "showAppOpenAd":if(isAppOpenAdShow){_appOpenAdLoadCallback(callbackContext);cordova.getActivity().runOnUiThread(()-> appOpenAd.show(mActivity));}else{callbackContext.error("The App Open Ad wasn't ready yet");}return true;case "loadInterstitialAd":cordova.getActivity().runOnUiThread(()->{final String adUnitId=args.optString(0);final boolean autoShow=args.optBoolean(1);try{this.interstitialAdUnitId=adUnitId;this.intAutoShow=autoShow;Bundle bundleExtra=new Bundle();bundleExtra.putString("npa",this.Npa);bundleExtra.putInt("is_designed_for_families",this.SetTagForChildDirectedTreatment);bundleExtra.putInt("under_age_of_consent",this.SetTagForUnderAgeOfConsent);bundleExtra.putString("max_ad_content_rating",this.SetMaxAdContentRating);AdRequest adRequest=new AdRequest.Builder().addNetworkExtrasBundle(AdMobAdapter.class,bundleExtra).build();InterstitialAd.load(mActivity,this.interstitialAdUnitId,adRequest,new InterstitialAdLoadCallback(){@Override public void onAdLoaded(@NonNull InterstitialAd interstitialAd){isinterstitialload=true;mInterstitialAd=interstitialAd;if(intAutoShow){_interstitialAdLoadCallback(callbackContext);cordova.getActivity().runOnUiThread(()-> mInterstitialAd.show(mActivity));}Log.i(TAG,"onAdLoaded");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.interstitial.loaded');");if(ResponseInfo){ResponseInfo responseInfo=interstitialAd.getResponseInfo();callbackContext.success(responseInfo.toString()+ '\n'+'\n'+bundleExtra);}mInterstitialAd.setOnPaidEventListener(adValue ->{long valueMicros=adValue.getValueMicros();String currencyCode=adValue.getCurrencyCode();int precision=adValue.getPrecisionType();String adUnitId=mInterstitialAd.getAdUnitId();JSONObject result=new JSONObject();try{result.put("micros",valueMicros);result.put("currency",currencyCode);result.put("precision",precision);result.put("adUnitId",adUnitId);callbackContext.success(result);}catch(JSONException e){callbackContext.error(e.getMessage());}cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.interstitial.revenue');");});}@Override public void onAdFailedToLoad(@NonNull LoadAdError loadAdError){mInterstitialAd=null;isinterstitialload=false;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.interstitial.failed.load');");callbackContext.error(loadAdError.toString());}});}catch(Exception e){callbackContext.error(e.toString());}});return true;case "showInterstitialAd":if(isinterstitialload){_interstitialAdLoadCallback(callbackContext);cordova.getActivity().runOnUiThread(()-> mInterstitialAd.show(mActivity));}else{callbackContext.error("The Interstitial ad wasn't ready yet");}return true;case "loadRewardedAd":cordova.getActivity().runOnUiThread(()->{final String adUnitId=args.optString(0);final boolean autoShow=args.optBoolean(1);try{this.rewardedAdUnitId=adUnitId;this.rewardedAutoShow=autoShow;Bundle bundleExtra=new Bundle();bundleExtra.putString("npa",this.Npa);bundleExtra.putInt("is_designed_for_families",this.SetTagForChildDirectedTreatment);bundleExtra.putInt("under_age_of_consent",this.SetTagForUnderAgeOfConsent);bundleExtra.putString("max_ad_content_rating",this.SetMaxAdContentRating);AdRequest adRequest=new AdRequest.Builder().addNetworkExtrasBundle(AdMobAdapter.class,bundleExtra).build();RewardedAd.load(mActivity,this.rewardedAdUnitId,adRequest,new RewardedAdLoadCallback(){public void onAdFailedToLoad(@NonNull LoadAdError loadAdError){rewardedAd=null;isrewardedload=false;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewarded.failed.load');");callbackContext.error(loadAdError.toString());}@Override public void onAdLoaded(@NonNull RewardedAd ad){rewardedAd=ad;isrewardedload=true;isAdSkip=0;if(rewardedAutoShow){isAdSkip=1;rewardedAd.show(mActivity,rewardItem ->{isAdSkip=2;int rewardAmount=rewardItem.getAmount();String rewardType=rewardItem.getType();cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.reward.userEarnedReward');");callbackContext.success("rewardAmount:"+rewardAmount+"rewardType:"+rewardType);});_rewardedAdLoadCallback(callbackContext);}cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewarded.loaded');");if(ResponseInfo){ResponseInfo responseInfo=ad.getResponseInfo();callbackContext.success(responseInfo.toString()+ '\n'+'\n'+bundleExtra);}rewardedAd.setOnPaidEventListener(adValue ->{long valueMicros=adValue.getValueMicros();String currencyCode=adValue.getCurrencyCode();int precision=adValue.getPrecisionType();String adUnitId=rewardedAd.getAdUnitId();JSONObject result=new JSONObject();try{result.put("micros",valueMicros);result.put("currency",currencyCode);result.put("precision",precision);result.put("adUnitId",adUnitId);callbackContext.success(result);}catch(JSONException e){callbackContext.error(e.getMessage());}cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewarded.revenue');");});}});}catch(Exception e){callbackContext.error(e.toString());}});return true;case "showRewardedAd":cordova.getActivity().runOnUiThread(()->{if(isrewardedload){isAdSkip=1;rewardedAd.show(mActivity,rewardItem ->{isAdSkip=2;int rewardAmount=rewardItem.getAmount();String rewardType=rewardItem.getType();cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.reward.userEarnedReward');");callbackContext.success("rewardAmount:"+rewardAmount+"rewardType:"+rewardType);});_rewardedAdLoadCallback(callbackContext);}else{callbackContext.error("The rewarded ad wasn't ready yet");}});return true;case "loadRewardedInterstitialAd":cordova.getActivity().runOnUiThread(()->{final String adUnitId=args.optString(0);final boolean autoShow=args.optBoolean(1);try{this.rewardedInterstitialAdUnitId=adUnitId;this.rIntAutoShow=autoShow;Bundle bundleExtra=new Bundle();bundleExtra.putString("npa",this.Npa);bundleExtra.putInt("is_designed_for_families",this.SetTagForChildDirectedTreatment);bundleExtra.putInt("under_age_of_consent",this.SetTagForUnderAgeOfConsent);bundleExtra.putString("max_ad_content_rating",this.SetMaxAdContentRating);AdRequest adRequest=new AdRequest.Builder().addNetworkExtrasBundle(AdMobAdapter.class,bundleExtra).build();RewardedInterstitialAd.load(mActivity,this.rewardedInterstitialAdUnitId,adRequest,new RewardedInterstitialAdLoadCallback(){@Override public void onAdLoaded(@NonNull RewardedInterstitialAd ad){rewardedInterstitialAd=ad;isrewardedInterstitialload=true;isAdSkip=0;if(rIntAutoShow){isAdSkip=1;rewardedInterstitialAd.show(mActivity,rewardItem ->{isAdSkip=2;int rewardAmount=rewardItem.getAmount();String rewardType=rewardItem.getType();cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInt.userEarnedReward');");callbackContext.success("rewardAmount:"+rewardAmount+"rewardType:"+rewardType);});_rewardedInterstitialAdLoadCallback(callbackContext);}cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInt.loaded');");if(ResponseInfo){ResponseInfo responseInfo=ad.getResponseInfo();callbackContext.success(responseInfo.toString()+ '\n'+'\n'+bundleExtra);}rewardedInterstitialAd.setOnPaidEventListener(adValue ->{long valueMicros=adValue.getValueMicros();String currencyCode=adValue.getCurrencyCode();int precision=adValue.getPrecisionType();String adUnitId=rewardedInterstitialAd.getAdUnitId();JSONObject result=new JSONObject();try{result.put("micros",valueMicros);result.put("currency",currencyCode);result.put("precision",precision);result.put("adUnitId",adUnitId);callbackContext.success(result);}catch(JSONException e){callbackContext.error(e.getMessage());}cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInt.revenue');");});}@Override public void onAdFailedToLoad(@NonNull LoadAdError loadAdError){rewardedInterstitialAd=null;isrewardedInterstitialload=false;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInt.failed.load');");callbackContext.error(loadAdError.toString());}});}catch(Exception e){callbackContext.error(e.toString());}});return true;case "showRewardedInterstitialAd":cordova.getActivity().runOnUiThread(()->{if(isrewardedInterstitialload){isAdSkip=1;rewardedInterstitialAd.show(mActivity,rewardItem ->{isAdSkip=2;int rewardAmount=rewardItem.getAmount();String rewardType=rewardItem.getType();cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInt.userEarnedReward');");callbackContext.success("rewardAmount:"+rewardAmount+"rewardType:"+rewardType);});}else{callbackContext.error("The rewarded ad wasn't ready yet");}_rewardedInterstitialAdLoadCallback(callbackContext);});return true;case "loadBannerAd":cordova.getActivity().runOnUiThread(()->{final String adUnitId=args.optString(0);final String position=args.optString(1);final String size=args.optString(2);final String collapsible=args.optString(3);final int adaptive_Width=args.optInt(4);final boolean autoShow=args.optBoolean(5);try{this.bannerAdUnitId=adUnitId;this.Position=position;this.Size=size;this.AdaptiveWidth=adaptive_Width;this.Collapsible=collapsible;this.bannerAutoShow=autoShow;if(lock){_loadBannerAd(adUnitId,position,size,collapsible,adaptive_Width);}}catch(Exception e){callbackContext.error(e.toString());}});return true;case "getConsentRequest":cordova.getActivity().runOnUiThread(()->{try{ConsentRequestParameters params=new ConsentRequestParameters .Builder().build();consentInformation=UserMessagingPlatform.getConsentInformation(mActivity);consentInformation.requestConsentInfoUpdate(mActivity,params,()->{cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.info.update');");if(consentInformation.getConsentStatus()==ConsentInformation.ConsentStatus.NOT_REQUIRED){callbackContext.success(ConsentInformation.ConsentStatus.NOT_REQUIRED);cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.status.not_required');");}else if(consentInformation.getConsentStatus()==ConsentInformation.ConsentStatus.OBTAINED){callbackContext.success(ConsentInformation.ConsentStatus.OBTAINED);cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.status.obtained');");}else if(consentInformation.getConsentStatus()==ConsentInformation.ConsentStatus.REQUIRED){callbackContext.success(ConsentInformation.ConsentStatus.REQUIRED);cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.status.required');");if(consentInformation.isConsentFormAvailable()){UserMessagingPlatform.loadConsentForm(cordova.getContext(),consentForm -> consentForm.show(cordova.getActivity(),formError ->{cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.failed.show');");callbackContext.error(String.valueOf(formError));}),formError -> callbackContext.error(formError.getMessage()));cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.failed.load.from');");}else{cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.form.not.available');");}}else if(consentInformation.getConsentStatus()==ConsentInformation.ConsentStatus.UNKNOWN){callbackContext.success(ConsentInformation.ConsentStatus.UNKNOWN);cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.status.unknown');");}},formError ->{cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.info.update.failed');");callbackContext.error(formError.getMessage());});}catch(Exception e){callbackContext.error(e.toString());}});return true;case "showPrivacyOptionsForm":cordova.getActivity().runOnUiThread(this::consentInfoUpdate);return true;case "consentReset":cordova.getActivity().runOnUiThread(()->{if(consentInformation!=null){consentInformation.reset();}});return true;case "getIabTfc":cordova.getActivity().runOnUiThread(()->{Context context=this.cordova.getActivity().getApplicationContext();SharedPreferences mPreferences=PreferenceManager.getDefaultSharedPreferences(context);int gdprApplies=mPreferences.getInt("IABTCF_gdprApplies",0);String consentString=mPreferences.getString("IABTCF_TCString","");String purposeConsents=mPreferences.getString("IABTCF_PurposeConsents","");JSONObject userInfoJson=new JSONObject();try{userInfoJson.put("IABTCF_TCString",consentString);userInfoJson.put("IABTCF_PurposeConsents",purposeConsents);userInfoJson.put("IABTCF_gdprApplies",gdprApplies);callbackContext.success(userInfoJson);cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.getIabTfc');");}catch(Exception e){callbackContext.error(e.toString());cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.getIabTfc.error');");}});return true;case "showBannerAd":cordova.getActivity().runOnUiThread(()->{if(isBannerPause==0){if(isBannerLoad){bannerViewLayout.addView(bannerView);isBannerShow=true;}}else if(isBannerPause==1){bannerView.setVisibility(View.VISIBLE);bannerView.resume();}});return true;case "hideBannerAd":cordova.getActivity().runOnUiThread(()->{if(isBannerShow){try{bannerView.setVisibility(View.GONE);bannerView.pause();isBannerLoad=false;isBannerPause=1;}catch(Exception e){callbackContext.error(e.toString());}}});return true;case "removeBannerAd":cordova.getActivity().runOnUiThread(()->{if(bannerView==null)return;RelativeLayout bannerViewLayout=(RelativeLayout)bannerView.getParent();if(bannerViewLayout!=null){bannerViewLayout.removeView(bannerView);bannerView.destroy();bannerView=null;isBannerLoad=false;isBannerShow=false;isBannerPause=2;lock=true;bannerAdImpression=0;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.banner.remove');");}});return true;}return false;}private void _loadBannerAd(String adUnitId,String position,String size,String collapsible,int adaptive_Width){try{if(bannerViewLayout==null){bannerViewLayout=new RelativeLayout(mActivity);RelativeLayout.LayoutParams params=new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.MATCH_PARENT);try{((ViewGroup)(((View)Objects.requireNonNull(webView.getClass().getMethod("getView").invoke(webView))).getParent())).addView(bannerViewLayout,params);}catch(Exception e){((ViewGroup)webView).addView(bannerViewLayout,params);}}bannerView=new AdView(mActivity);if(Objects.equals(size,"BANNER")){bannerView.setAdSize(AdSize.BANNER);}else if(Objects.equals(size,"LARGE_BANNER")){bannerView.setAdSize(AdSize.LARGE_BANNER);}else if(Objects.equals(size,"MEDIUM_RECTANGLE")){bannerView.setAdSize(AdSize.MEDIUM_RECTANGLE);}else if(Objects.equals(size,"FULL_BANNER")){bannerView.setAdSize(AdSize.FULL_BANNER);}else if(Objects.equals(size,"LEADERBOARD")){bannerView.setAdSize(AdSize.LEADERBOARD);}else if(Objects.equals(size,"FLUID")){bannerView.setAdSize(AdSize.FLUID);}else if(Objects.equals(size,"ANCHORED")){bannerView.setAdSize(AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(mActivity,adaptive_Width));}else if(Objects.equals(size,"IN_LINE")){bannerView.setAdSize(AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize(mActivity,adaptive_Width));}else if(Objects.equals(size,"FULL_WIDTH")){bannerView.setAdSize(AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize(mActivity,AdSize.FULL_WIDTH));}else{bannerView.setAdSize(AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(mActivity,AdSize.FULL_WIDTH));}bannerView.setAdUnitId(adUnitId);Bundle bundleExtra=new Bundle();if(isCollapsible){bundleExtra.putString("collapsible",collapsible);}bundleExtra.putString("npa",this.Npa);bundleExtra.putInt("is_designed_for_families",this.SetTagForChildDirectedTreatment);bundleExtra.putInt("under_age_of_consent",this.SetTagForUnderAgeOfConsent);bundleExtra.putString("max_ad_content_rating",this.SetMaxAdContentRating);AdRequest adRequest=new AdRequest.Builder().addNetworkExtrasBundle(AdMobAdapter.class,bundleExtra).build();bannerView.loadAd(adRequest);bannerView.setAdListener(bannerAdListener);RelativeLayout.LayoutParams bannerParams=new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);switch(position){case "top-right":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);bannerParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);break;case "top-center":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);bannerParams.addRule(RelativeLayout.CENTER_HORIZONTAL);break;case "left":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);bannerParams.addRule(RelativeLayout.CENTER_VERTICAL);break;case "center":bannerParams.addRule(RelativeLayout.CENTER_HORIZONTAL);bannerParams.addRule(RelativeLayout.CENTER_VERTICAL);break;case "right":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);bannerParams.addRule(RelativeLayout.CENTER_VERTICAL);break;case "bottom-center":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);bannerParams.addRule(RelativeLayout.CENTER_HORIZONTAL);break;case "bottom-right":bannerParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);bannerParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);break;default:bannerParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);bannerParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);break;}bannerView.setLayoutParams(bannerParams);bannerViewLayout.bringToFront();}catch(Exception e){PUBLIC_CALLBACKS.error(e.toString());}}private final AdListener bannerAdListener=new AdListener(){@Override public void onAdClicked(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.banner.click');");}@Override public void onAdClosed(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.banner.close');");}@Override public void onAdFailedToLoad(@NonNull LoadAdError adError){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.banner.failed.load');");isBannerLoad=false;isBannerShow=false;lock=true;PUBLIC_CALLBACKS.error(adError.toString());}@Override public void onAdImpression(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.banner.impression');");}@Override public void onAdLoaded(){isBannerLoad=true;bannerAdImpression=1;isBannerPause=0;lock=false;if(bannerAutoShow){bannerViewLayout.addView(bannerView);isBannerPause=0;}cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.banner.load');");bannerView.setOnPaidEventListener(bannerPaidAdListener);if(ResponseInfo){Bundle bundleExtra=new Bundle();bundleExtra.putString("npa",Npa);bundleExtra.putInt("is_designed_for_families",SetTagForChildDirectedTreatment);bundleExtra.putInt("under_age_of_consent",SetTagForUnderAgeOfConsent);bundleExtra.putString("max_ad_content_rating",SetMaxAdContentRating);try{ResponseInfo responseInfo=bannerView.getResponseInfo();assert responseInfo!=null;PUBLIC_CALLBACKS.success(responseInfo.toString()+ '\n'+'\n'+bundleExtra);}catch(NullPointerException e){e.printStackTrace();}}}@Override public void onAdOpened(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.banner.open');");}};private final OnPaidEventListener bannerPaidAdListener=new OnPaidEventListener(){@Override public void onPaidEvent(@NonNull AdValue adValue){long valueMicros=adValue.getValueMicros();String currencyCode=adValue.getCurrencyCode();int precision=adValue.getPrecisionType();String adUnitId=bannerView.getAdUnitId();JSONObject result=new JSONObject();try{result.put("micros",valueMicros);result.put("currency",currencyCode);result.put("precision",precision);result.put("adUnitId",adUnitId);isBannerLoad=false;PUBLIC_CALLBACKS.success(result);cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.banner.revenue');");}catch(JSONException e){PUBLIC_CALLBACKS.error(e.getMessage());}}};public boolean isPrivacyOptionsRequired(){return consentInformation.getPrivacyOptionsRequirementStatus()==ConsentInformation.PrivacyOptionsRequirementStatus.REQUIRED;}private void consentInfoUpdate(){ConsentRequestParameters params=new ConsentRequestParameters .Builder().setTagForUnderAgeOfConsent(false).build();consentInformation=UserMessagingPlatform.getConsentInformation(mActivity);consentInformation.requestConsentInfoUpdate(mActivity,params,(ConsentInformation.OnConsentInfoUpdateSuccessListener)this::OptionsMenu,(ConsentInformation.OnConsentInfoUpdateFailureListener)requestConsentError ->{PUBLIC_CALLBACKS.error(requestConsentError.getMessage());});}private void OptionsMenu(){try{UserMessagingPlatform.loadAndShowConsentFormIfRequired(mActivity,(ConsentForm.OnConsentFormDismissedListener)loadAndShowError ->{if(loadAndShowError!=null){PUBLIC_CALLBACKS.error(loadAndShowError.getMessage());}if(isPrivacyOptionsRequired()){invalidateOptionsMenu();}});}catch(Exception e){throw new RuntimeException(e);}}private void invalidateOptionsMenu(){UserMessagingPlatform.showPrivacyOptionsForm(mActivity,formError ->{if(formError!=null){PUBLIC_CALLBACKS.error(formError.getMessage());}});}private void _appOpenAdLoadCallback(CallbackContext callbackContext){appOpenAd.setFullScreenContentCallback(new FullScreenContentCallback(){@Override public void onAdDismissedFullScreenContent(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.appOpenAd.dismissed');");View mainView=getView();if(mainView!=null){mainView.requestFocus();}}@Override public void onAdFailedToShowFullScreenContent(@NonNull AdError adError){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.appOpenAd.failed.show');");callbackContext.error(adError.toString());appOpenAd=null;}@Override public void onAdShowedFullScreenContent(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.appOpenAd.show');");}});}private void _interstitialAdLoadCallback(CallbackContext callbackContext){mInterstitialAd.setFullScreenContentCallback(new FullScreenContentCallback(){@Override public void onAdClicked(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.interstitial.click');");}@Override public void onAdDismissedFullScreenContent(){mInterstitialAd=null;isinterstitialload=false;View mainView=getView();if(mainView!=null){mainView.requestFocus();}cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.interstitial.dismissed');");}@Override public void onAdFailedToShowFullScreenContent(@NonNull AdError adError){mInterstitialAd=null;isinterstitialload=false;callbackContext.error(adError.toString());cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.interstitial.failed.show');");}@Override public void onAdImpression(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.interstitial.impression');");}@Override public void onAdShowedFullScreenContent(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.interstitial.show');");}});}private void _rewardedAdLoadCallback(CallbackContext callbackContext){rewardedAd.setFullScreenContentCallback(new FullScreenContentCallback(){@Override public void onAdClicked(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewarded.click');");}@Override public void onAdDismissedFullScreenContent(){if(isAdSkip!=2){rewardedAd=null;isrewardedload=false;View mainView=getView();if(mainView!=null){mainView.requestFocus();}cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewarded.ad.skip');");}rewardedAd=null;isrewardedload=false;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewarded.dismissed');");}@Override public void onAdFailedToShowFullScreenContent(@NonNull AdError adError){rewardedAd=null;isrewardedload=false;callbackContext.error(adError.toString());cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewarded.failed.show');");}@Override public void onAdImpression(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewarded.impression');");}@Override public void onAdShowedFullScreenContent(){isAdSkip=1;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewarded.show');");}});}private void _rewardedInterstitialAdLoadCallback(CallbackContext callbackContext){rewardedInterstitialAd.setFullScreenContentCallback(new FullScreenContentCallback(){@Override public void onAdClicked(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInt.click');");}@Override public void onAdDismissedFullScreenContent(){if(isAdSkip!=2){rewardedInterstitialAd=null;isrewardedInterstitialload=false;cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInt.ad.skip');");}rewardedInterstitialAd=null;isrewardedInterstitialload=false;View mainView=getView();if(mainView!=null){mainView.requestFocus();}cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInt.dismissed');");}@Override public void onAdFailedToShowFullScreenContent(@NonNull AdError adError){rewardedInterstitialAd=null;isrewardedInterstitialload=false;callbackContext.error(adError.toString());cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInt.failed.show');");}@Override public void onAdImpression(){cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInt.impression');");}@Override public void onAdShowedFullScreenContent(){isAdSkip=1;Log.d(TAG,"Ad showed fullscreen content.");cWebView.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInt.showed');");}});}public void _globalSettings(){MobileAds.setAppMuted(this.SetAppMuted);MobileAds.setAppVolume(this.SetAppVolume);MobileAds.enableSameAppKey(this.EnableSameAppKey);}public void _Targeting(){RequestConfiguration.Builder requestConfiguration=MobileAds.getRequestConfiguration().toBuilder();if(SetTagForChildDirectedTreatment==-1){requestConfiguration.setTagForChildDirectedTreatment(RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_UNSPECIFIED);}else if(SetTagForChildDirectedTreatment==0){requestConfiguration.setTagForChildDirectedTreatment(RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_FALSE);}else if(SetTagForChildDirectedTreatment==1){requestConfiguration.setTagForChildDirectedTreatment(RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_TRUE);}else{requestConfiguration.setTagForChildDirectedTreatment(RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_UNSPECIFIED);}if(SetTagForUnderAgeOfConsent==-1){requestConfiguration.setTagForUnderAgeOfConsent(RequestConfiguration.TAG_FOR_UNDER_AGE_OF_CONSENT_UNSPECIFIED);}else if(SetTagForUnderAgeOfConsent==0){requestConfiguration.setTagForUnderAgeOfConsent(RequestConfiguration.TAG_FOR_UNDER_AGE_OF_CONSENT_FALSE);}else if(SetTagForUnderAgeOfConsent==1){requestConfiguration.setTagForUnderAgeOfConsent(RequestConfiguration.TAG_FOR_UNDER_AGE_OF_CONSENT_TRUE);}else{requestConfiguration.setTagForUnderAgeOfConsent(RequestConfiguration.TAG_FOR_UNDER_AGE_OF_CONSENT_UNSPECIFIED);}if(Objects.equals(SetMaxAdContentRating,"")){requestConfiguration.setMaxAdContentRating(RequestConfiguration.MAX_AD_CONTENT_RATING_UNSPECIFIED);}else if(Objects.equals(SetMaxAdContentRating,"T")){requestConfiguration.setMaxAdContentRating(RequestConfiguration.MAX_AD_CONTENT_RATING_T);}else if(Objects.equals(SetMaxAdContentRating,"PG")){requestConfiguration.setMaxAdContentRating(RequestConfiguration.MAX_AD_CONTENT_RATING_PG);}else if(Objects.equals(SetMaxAdContentRating,"MA")){requestConfiguration.setMaxAdContentRating(RequestConfiguration.MAX_AD_CONTENT_RATING_MA);}else if(Objects.equals(SetMaxAdContentRating,"G")){requestConfiguration.setMaxAdContentRating(RequestConfiguration.MAX_AD_CONTENT_RATING_G);}else{requestConfiguration.setTagForUnderAgeOfConsent(RequestConfiguration.TAG_FOR_UNDER_AGE_OF_CONSENT_UNSPECIFIED);}MobileAds.setRequestConfiguration(requestConfiguration.build());}private View getView(){if(View.class.isAssignableFrom(CordovaWebView.class)){return(View)cWebView;}return cordova.getActivity().getWindow().getDecorView().findViewById(android.R.id.content);}@Override public void onPause(boolean multitasking){if(bannerView!=null){bannerView.pause();}super.onPause(multitasking);}@Override public void onResume(boolean multitasking){super.onResume(multitasking);if(bannerView!=null){bannerView.resume();}}@Override public void onDestroy(){if(bannerView!=null){bannerView.destroy();bannerView=null;}if(bannerViewLayout!=null){ViewGroup parentView=(ViewGroup)bannerViewLayout.getParent();if(parentView!=null){parentView.removeView(bannerViewLayout);}bannerViewLayout=null;}bannerAdImpression=0;super.onDestroy();}}
@@ -0,0 +1,33 @@
1
+ #import <UIKit/UIKit.h>
2
+ #import <Cordova/CDVPlugin.h>
3
+ #import <GoogleMobileAds/GoogleMobileAds.h>
4
+ #import <UserMessagingPlatform/UserMessagingPlatform.h>
5
+ @interface emiAdmobPlugin : CDVPlugin<GADBannerViewDelegate, GADFullScreenContentDelegate>{}
6
+ @property(nonatomic, strong) GADAppOpenAd *appOpenAd;
7
+ @property(nonatomic, strong) GADBannerView *bannerView;
8
+ @property(nonatomic, strong) GADInterstitialAd *interstitial;
9
+ @property(nonatomic, strong) GADRewardedInterstitialAd* rewardedInterstitialAd;
10
+ @property(nonatomic, strong) GADRewardedAd *rewardedAd;
11
+ @property(nonatomic, readonly) BOOL isPrivacyOptionsRequired;
12
+ - (void)initialize:(CDVInvokedUrlCommand *)command;
13
+ - (void)requestIDFA:(CDVInvokedUrlCommand *)command;
14
+ - (void)showPrivacyOptionsForm:(CDVInvokedUrlCommand *)command;
15
+ - (void)getConsentRequest:(CDVInvokedUrlCommand *)command;
16
+ - (void)consentReset:(CDVInvokedUrlCommand *)command;
17
+ - (void)getIabTfc:(CDVInvokedUrlCommand *)command;
18
+ - (void)loadAppOpenAd:(CDVInvokedUrlCommand *)command;
19
+ - (void)showAppOpenAd:(CDVInvokedUrlCommand *)command;
20
+ - (void)loadBannerAdIOS:(CDVInvokedUrlCommand *)command;
21
+ - (void)showBannerAd:(CDVInvokedUrlCommand *)command;
22
+ - (void)hiddenAd:(CDVInvokedUrlCommand *)command;
23
+ - (void)removeBannerAd:(CDVInvokedUrlCommand *)command;
24
+ - (void)loadInterstitialAd:(CDVInvokedUrlCommand *)command;
25
+ - (void)showInterstitialAd:(CDVInvokedUrlCommand *)command;
26
+ - (void)loadRewardedInterstitialAd:(CDVInvokedUrlCommand *)command;
27
+ - (void)showRewardedInterstitialAd:(CDVInvokedUrlCommand *)command;
28
+ - (void)loadRewardedAd:(CDVInvokedUrlCommand *)command;
29
+ - (void)showRewardedAd:(CDVInvokedUrlCommand *)command;
30
+ - (void) fireEvent:(NSString *)obj event:(NSString *)eventName withData:(NSString *)jsonStr;
31
+ @end
32
+
33
+
@@ -0,0 +1,554 @@
1
+
2
+ #import "emiAdmobPlugin.h"
3
+ #import <Cordova/CDVPlugin.h>
4
+ #import <UserMessagingPlatform/UserMessagingPlatform.h>
5
+ #import <AppTrackingTransparency/AppTrackingTransparency.h>
6
+ #import <AdSupport/AdSupport.h>
7
+ #import <Foundation/Foundation.h>
8
+ @implementation emiAdmobPlugin
9
+ @synthesize appOpenAd;
10
+ @synthesize bannerView;
11
+ @synthesize interstitial;
12
+ @synthesize rewardedInterstitialAd;
13
+ @synthesize rewardedAd;
14
+ @synthesize isPrivacyOptionsRequired;
15
+ int idfaStatus = 0;
16
+ int fromStatus = 0;
17
+ int adFormat = 0;
18
+ int adWidth = 320;
19
+ BOOL isIAB = NO;
20
+ - (void)pluginInitialize {
21
+ isIAB = YES;
22
+ [[NSUserDefaults standardUserDefaults] synchronize];
23
+ }
24
+ - (void)requestIDFA:(CDVInvokedUrlCommand*)command {
25
+ CDVPluginResult *pluginResult;
26
+ NSString *callbackId = command.callbackId;
27
+ if (@available(iOS 14, *)) {
28
+ [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
29
+ if (status == ATTrackingManagerAuthorizationStatusDenied) {
30
+ idfaStatus = ATTrackingManagerAuthorizationStatusDenied;
31
+ } else if (status == ATTrackingManagerAuthorizationStatusAuthorized) {
32
+ idfaStatus = ATTrackingManagerAuthorizationStatusAuthorized;
33
+ } else if (status == ATTrackingManagerAuthorizationStatusRestricted) {
34
+ idfaStatus = ATTrackingManagerAuthorizationStatusRestricted;
35
+ } else if (status == ATTrackingManagerAuthorizationStatusNotDetermined) {
36
+ idfaStatus = ATTrackingManagerAuthorizationStatusNotDetermined;
37
+ }
38
+ }];
39
+ [self fireEvent:@"" event:@"on.getIDFA" withData:nil];
40
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:idfaStatus];
41
+ } else {
42
+ [self fireEvent:@"" event:@"on.getIDFA.error" withData:nil];
43
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
44
+ }
45
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
46
+ }
47
+ - (void)getConsentRequest:(CDVInvokedUrlCommand*)command {
48
+ CDVPluginResult *pluginResult;
49
+ NSString *callbackId = command.callbackId;
50
+ UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init];
51
+ // UMPDebugSettings *debugSettings = [[UMPDebugSettings alloc] init];
52
+ // debugSettings.testDeviceIdentifiers = @[@"59156CDC-B042-4D81-A9FA-900869782912"];
53
+ // parameters.debugSettings = debugSettings;
54
+ // debugSettings.geography = UMPDebugGeographyEEA;
55
+ BOOL tagForUnderAgeOfConsent = [[command argumentAtIndex:0] boolValue];
56
+ parameters.tagForUnderAgeOfConsent = tagForUnderAgeOfConsent;
57
+ [UMPConsentInformation.sharedInstance
58
+ requestConsentInfoUpdateWithParameters:parameters
59
+ completionHandler:^(NSError *_Nullable requestConsentError) {
60
+ if (requestConsentError) {
61
+ // Consent gathering failed.
62
+ NSLog(@"Error: %@", requestConsentError.localizedDescription);
63
+ return;
64
+ }
65
+ [UMPConsentForm loadAndPresentIfRequiredFromViewController:self.viewController
66
+ completionHandler:^(NSError *loadAndPresentError) {
67
+ if (loadAndPresentError) {
68
+ // Consent gathering failed.
69
+ NSLog(@"Error: %@", loadAndPresentError.localizedDescription);
70
+ return;
71
+ }
72
+ UMPFormStatus formStatus = UMPConsentInformation.sharedInstance.formStatus;
73
+ if (formStatus == UMPFormStatusUnknown) {
74
+ fromStatus = 0;
75
+ } else if (formStatus == UMPFormStatusAvailable) {
76
+ fromStatus = 1;
77
+
78
+ } else if (formStatus == UMPFormStatusUnavailable) {
79
+ fromStatus = 2;
80
+ }
81
+ [self fireEvent:@"" event:@"on.get.from.status" withData:nil];
82
+ }];
83
+
84
+ }];
85
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:fromStatus];
86
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
87
+ }
88
+ - (void)showPrivacyOptionsForm:(CDVInvokedUrlCommand*)command {
89
+ UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init];
90
+ // UMPDebugSettings *debugSettings = [[UMPDebugSettings alloc] init];
91
+ // debugSettings.testDeviceIdentifiers = @[@"59156CDC-B042-4D81-A9FA-900869782912"];
92
+ // parameters.debugSettings = debugSettings;
93
+ // debugSettings.geography = UMPDebugGeographyEEA;
94
+ BOOL tagForUnderAgeOfConsent = [[command argumentAtIndex:0] boolValue];
95
+ parameters.tagForUnderAgeOfConsent = tagForUnderAgeOfConsent;
96
+ [UMPConsentInformation.sharedInstance
97
+ requestConsentInfoUpdateWithParameters:parameters
98
+ completionHandler:^(NSError *_Nullable requestConsentError) {
99
+ // ...
100
+ [UMPConsentForm loadAndPresentIfRequiredFromViewController:self.viewController
101
+ completionHandler:^(NSError *loadAndPresentError) {
102
+ }];
103
+ [self isPrivacyOptionsRequired];
104
+ }];
105
+ [UMPConsentForm presentPrivacyOptionsFormFromViewController:self.viewController completionHandler:^(NSError * _Nullable formError) {
106
+ if (formError) {
107
+ // Handle the error.
108
+ NSLog(@"Error: %@", formError.localizedDescription);
109
+ [self fireEvent:@"" event:@"on.getPrivacyOptionsFrom.error" withData:nil];
110
+ }
111
+ }];
112
+ }
113
+ - (BOOL)isPrivacyOptionsRequired {
114
+ return UMPConsentInformation.sharedInstance.privacyOptionsRequirementStatus ==
115
+ UMPPrivacyOptionsRequirementStatusRequired;
116
+ }
117
+ - (void)getIabTfc:(CDVInvokedUrlCommand*)command {
118
+ CDVPluginResult *pluginResult;
119
+ NSString *callbackId = command.callbackId;
120
+ if (isIAB == 1) {
121
+ NSMutableDictionary* result = [[NSMutableDictionary alloc] init];
122
+ NSInteger CmpSdkVersion = [NSUserDefaults.standardUserDefaults
123
+ integerForKey:@"IABTCF_CmpSdkVersion"] ?: 2;
124
+ NSString *purposeConsents = [NSUserDefaults.standardUserDefaults
125
+ stringForKey:@"IABTCF_PurposeConsents"] ?: @"";
126
+ NSString *tCString = [NSUserDefaults.standardUserDefaults
127
+ stringForKey:@"IABTCF_TCString"] ?: @"";
128
+ NSInteger gdprApplies = [NSUserDefaults.standardUserDefaults
129
+ integerForKey:@"IABTCF_gdprApplies"] ?: 0;
130
+ [result setObject:[NSNumber numberWithInteger:CmpSdkVersion] forKey:@"IABTCF_CmpSdkVersion"];
131
+ [result setObject:[NSNumber numberWithInteger:gdprApplies] forKey:@"IABTCF_gdprApplies"];
132
+ [result setObject:[NSString stringWithString:purposeConsents] forKey:@"IABTCF_PurposeConsents"];
133
+ [result setObject:[NSString stringWithString:tCString] forKey:@"IABTCF_TCString"];
134
+
135
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:result];
136
+ [self fireEvent:@"" event:@"on.getIabTfc" withData:nil];
137
+ } else {
138
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
139
+ }
140
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
141
+ }
142
+ - (void)consentReset:(CDVInvokedUrlCommand*)command {
143
+ CDVPluginResult *pluginResult;
144
+ NSString *callbackId = command.callbackId;
145
+ @try {
146
+ [UMPConsentInformation.sharedInstance reset];
147
+ }@catch (NSException *exception) {
148
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:exception.reason];
149
+ }
150
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
151
+ }
152
+ - (void)globalSettings:(CDVInvokedUrlCommand*)command {
153
+ CDVPluginResult *pluginResult;
154
+ NSString *callbackId = command.callbackId;
155
+ BOOL setAppMuted = [[command argumentAtIndex:0] boolValue];
156
+ float setAppVolume = [[command argumentAtIndex:1] floatValue];
157
+ @try {
158
+ GADMobileAds.sharedInstance.applicationVolume = setAppVolume;
159
+ GADMobileAds.sharedInstance.applicationMuted = setAppMuted;
160
+ }@catch (NSException *exception) {
161
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:exception.reason];
162
+ }
163
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
164
+ }
165
+ - (void)targeting:(CDVInvokedUrlCommand*)command {
166
+ CDVPluginResult *pluginResult;
167
+ NSString *callbackId = command.callbackId;
168
+ NSNumber *TagForChildDirectedTreatment = [command argumentAtIndex:0];
169
+ NSNumber *tagForUnderAgeOfConsent = [command argumentAtIndex:1];
170
+ NSString *maxAdContentRating = [command argumentAtIndex:2];
171
+ @try {
172
+ GADRequestConfiguration *requestConfiguration = GADMobileAds.sharedInstance.requestConfiguration;
173
+ requestConfiguration.tagForChildDirectedTreatment = TagForChildDirectedTreatment;
174
+ requestConfiguration.tagForUnderAgeOfConsent = tagForUnderAgeOfConsent;
175
+ requestConfiguration.maxAdContentRating = maxAdContentRating;
176
+ }@catch (NSException *exception) {
177
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:exception.reason];
178
+ }
179
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
180
+ }
181
+ - (void)initialize:(CDVInvokedUrlCommand*)command {
182
+ GADMobileAds *ads = [GADMobileAds sharedInstance];
183
+ [ads startWithCompletionHandler:^(GADInitializationStatus *status) {
184
+ // Optional: Log each adapter's initialization latency.
185
+ NSDictionary *adapterStatuses = [status adapterStatusesByClassName];
186
+ for (NSString *adapter in adapterStatuses) {
187
+ GADAdapterStatus *adapterStatus = adapterStatuses[adapter];
188
+ NSLog(@"Adapter Name: %@, Description: %@, Latency: %f", adapter,
189
+ adapterStatus.description, adapterStatus.latency);
190
+ }
191
+ [self fireEvent:@"" event:@"on.sdkInitialization" withData:nil];
192
+ }];
193
+ }
194
+ - (GADAdSize)__AdSizeFromString:(NSString *)size
195
+ {
196
+ if ([size isEqualToString:@"Anchored_adaptive"]) {
197
+ return GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(adWidth);
198
+ } else if ([size isEqualToString:@"Inline_adaptive"]) {
199
+ return GADCurrentOrientationInlineAdaptiveBannerAdSizeWithWidth(adWidth);
200
+ } else if ([size isEqualToString:@"BANNER"]) {
201
+ return GADAdSizeBanner;
202
+ } else if ([size isEqualToString:@"LARGE_BANNER"]) {
203
+ return GADAdSizeLargeBanner;
204
+ } else if ([size isEqualToString:@"FULL_BANNER"]) {
205
+ return GADAdSizeFullBanner;
206
+ } else if ([size isEqualToString:@"LEADERBOARD"]) {
207
+ return GADAdSizeLeaderboard;
208
+ } else {
209
+ return GADAdSizeBanner;
210
+ }
211
+ }
212
+ - (void)loadBannerAdIOS:(CDVInvokedUrlCommand*)command {
213
+ if(self.bannerView) {
214
+ NSLog(@"Admob banner has been initing");
215
+ return;
216
+ }
217
+ CDVPluginResult *pluginResult;
218
+ NSString *callbackId = command.callbackId;
219
+ adFormat = 3;
220
+ if (adFormat == 3) {
221
+ UIView *parentView = [self.webView superview];
222
+ NSString* adUnitId = [command.arguments objectAtIndex:0];
223
+ NSNumber* x = [command.arguments objectAtIndex:1];
224
+ NSNumber* y = [command.arguments objectAtIndex:2];
225
+ NSString* size = [command.arguments objectAtIndex:3];
226
+ NSNumber* adaptiveWidth = [command.arguments objectAtIndex:4];
227
+ NSString* collapsible = [command.arguments objectAtIndex:5];
228
+ int intValue = [adaptiveWidth intValue];
229
+ adWidth = intValue;
230
+ float posX = [x floatValue];
231
+ float posY = [y floatValue];
232
+ GADAdSize sizes = [self __AdSizeFromString:size];
233
+ CGPoint origin = CGPointMake(posX,posY);
234
+ self.bannerView = [[GADBannerView alloc]
235
+ initWithAdSize:sizes
236
+ origin:origin];
237
+ GADExtras *extras = [[GADExtras alloc] init];
238
+ extras.additionalParameters = @{@"collapsible" : collapsible};
239
+ self.bannerView.adUnitID = adUnitId;
240
+ self.bannerView.rootViewController = self.viewController;
241
+ self.bannerView.delegate = self;
242
+ GADRequest *request = [GADRequest request];
243
+ [self.bannerView loadRequest:request];
244
+ [request registerAdNetworkExtras:extras];
245
+ self.bannerView.hidden = YES;
246
+ [parentView addSubview:self.bannerView];
247
+ [parentView bringSubviewToFront:self.bannerView];
248
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
249
+ } else {
250
+ NSLog(@"Admob Option invalid for banner");
251
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
252
+ }
253
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
254
+ }
255
+ - (void)showBannerAd:(CDVInvokedUrlCommand*)command {
256
+ CDVPluginResult *pluginResult;
257
+ NSString *callbackId = command.callbackId;
258
+ if(self.bannerView) {
259
+ self.bannerView.hidden = NO;
260
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
261
+ } else {
262
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
263
+ }
264
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
265
+ }
266
+ - (void)hiddenAd:(CDVInvokedUrlCommand*)command {
267
+ CDVPluginResult *pluginResult;
268
+ NSString *callbackId = command.callbackId;
269
+ if(self.bannerView) {
270
+ self.bannerView.hidden = YES;
271
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
272
+ } else {
273
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
274
+ }
275
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
276
+ }
277
+
278
+ - (void)removeBannerAd:(CDVInvokedUrlCommand*)command {
279
+ CDVPluginResult *pluginResult;
280
+ NSString *callbackId = command.callbackId;
281
+ if(self.bannerView) {
282
+ self.bannerView.hidden = YES;
283
+ [self.bannerView removeFromSuperview];
284
+ self.bannerView = nil;
285
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
286
+ } else {
287
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
288
+ }
289
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
290
+ }
291
+ - (void)loadAppOpenAd:(CDVInvokedUrlCommand *)command {
292
+ CDVPluginResult *pluginResult;
293
+ NSString *callbackId = command.callbackId;
294
+ NSString* adUnitId = [command.arguments objectAtIndex:0];
295
+ adFormat = 1;
296
+ self.appOpenAd = nil;
297
+ if (adFormat == 1){
298
+ [GADAppOpenAd loadWithAdUnitID:adUnitId
299
+ request:[GADRequest request]
300
+ orientation:UIInterfaceOrientationPortrait
301
+ completionHandler:^(GADAppOpenAd *ad, NSError *error) {
302
+ if (error) {
303
+ [self fireEvent:@"" event:@"on.appOpenAd.failed.loaded" withData:nil];
304
+ NSLog(@"Failed to load App Open Ad ad with error: %@", [error localizedDescription]);
305
+ return;
306
+ }
307
+ self.appOpenAd = ad;
308
+ self.appOpenAd.fullScreenContentDelegate = self;
309
+ [self fireEvent:@"" event:@"on.appOpenAd.loaded" withData:nil];
310
+ }];
311
+ }
312
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
313
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
314
+ }
315
+ - (void)showAppOpenAd:(CDVInvokedUrlCommand *)command {
316
+ CDVPluginResult *pluginResult;
317
+ NSString *callbackId = command.callbackId;
318
+ if (self.appOpenAd && [self.appOpenAd
319
+ canPresentFromRootViewController:self.viewController
320
+ error:nil]) { [self.appOpenAd presentFromRootViewController:self.viewController];
321
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
322
+ } else {
323
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
324
+ [self fireEvent:@"" event:@"on.appOpenAd.failed.show" withData:nil];
325
+ }
326
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
327
+ }
328
+ - (void)loadInterstitialAd:(CDVInvokedUrlCommand *)command {
329
+ CDVPluginResult *pluginResult;
330
+ NSString *callbackId = command.callbackId;
331
+ NSString* adUnitId = [command.arguments objectAtIndex:0];
332
+ adFormat = 2;
333
+ if (adFormat == 2){
334
+ GADRequest *request = [GADRequest request];
335
+ [GADInterstitialAd
336
+ loadWithAdUnitID:adUnitId
337
+ request:request
338
+ completionHandler:^(GADInterstitialAd *ad, NSError *error) {
339
+ if (error) {
340
+ NSLog(@"Failed to load interstitial ad with error: %@", [error localizedDescription]);
341
+ return;
342
+ }
343
+ self.interstitial = ad;
344
+ self.interstitial.fullScreenContentDelegate = self;
345
+ [self fireEvent:@"" event:@"on.interstitial.loaded" withData:nil];
346
+ }];
347
+ }
348
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
349
+
350
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
351
+ }
352
+ - (void)showInterstitialAd:(CDVInvokedUrlCommand *)command {
353
+ CDVPluginResult *pluginResult;
354
+ NSString *callbackId = command.callbackId;
355
+ if (self.interstitial && [self.interstitial
356
+ canPresentFromRootViewController:self.viewController error:nil]) {
357
+
358
+ [self.interstitial presentFromRootViewController:self.viewController];
359
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
360
+ } else {
361
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
362
+ [self fireEvent:@"" event:@"on.interstitial.failed.show" withData:nil];
363
+ }
364
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
365
+ }
366
+ - (void)loadRewardedInterstitialAd:(CDVInvokedUrlCommand*)command {
367
+ CDVPluginResult *pluginResult;
368
+ NSString *callbackId = command.callbackId;
369
+ NSString* adUnitId = [command.arguments objectAtIndex:0];
370
+ adFormat = 4;
371
+ if (adFormat == 4){
372
+ GADRequest *request = [GADRequest request];
373
+ [GADRewardedInterstitialAd
374
+ loadWithAdUnitID:adUnitId
375
+ request:request
376
+ completionHandler:^(GADRewardedInterstitialAd *ad, NSError *error) {
377
+ if (error) {
378
+ NSLog(@"Rewarded ad failed to load with error: %@", [error localizedDescription]);
379
+ return;
380
+ }
381
+ self.rewardedInterstitialAd = ad;
382
+ NSLog(@"Rewarded ad loaded.");
383
+ self.rewardedInterstitialAd.fullScreenContentDelegate = self;
384
+ [self fireEvent:@"" event:@"on.rewardedInt.loaded" withData:nil];
385
+ }];
386
+ }
387
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
388
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
389
+ }
390
+ -(void)showRewardedInterstitialAd:(CDVInvokedUrlCommand *)command {
391
+ CDVPluginResult *pluginResult;
392
+ NSString *callbackId = command.callbackId;
393
+ if (self.rewardedInterstitialAd && [self.rewardedInterstitialAd canPresentFromRootViewController:self.viewController error:nil]) {
394
+
395
+ [self.rewardedInterstitialAd presentFromRootViewController:self.viewController
396
+ userDidEarnRewardHandler:^{
397
+ GADAdReward *reward =
398
+ self.rewardedInterstitialAd.adReward;
399
+ [self fireEvent:@"" event:@"on.rewardedInt.userEarnedReward" withData:nil];
400
+
401
+ NSString *rewardMessage = [NSString stringWithFormat:@"Reward received with "
402
+ @"currency %@ , amount %ld",
403
+ reward.type, [reward.amount longValue]];
404
+ NSLog(@"%@", rewardMessage);
405
+
406
+ }];
407
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
408
+ } else {
409
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
410
+ [self fireEvent:@"" event:@"on.rewardedInt.failed.show" withData:nil];
411
+ }
412
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
413
+ }
414
+ - (void)loadRewardedAd:(CDVInvokedUrlCommand*)command {
415
+
416
+ CDVPluginResult *pluginResult;
417
+ NSString *callbackId = command.callbackId;
418
+ NSString* adUnitId = [command.arguments objectAtIndex:0];
419
+ adFormat = 3;
420
+ if (adFormat == 3){
421
+ GADRequest *request = [GADRequest request];
422
+ [GADRewardedAd
423
+ loadWithAdUnitID:adUnitId
424
+ request:request
425
+ completionHandler:^(GADRewardedAd *ad, NSError *error) {
426
+ if (error) {
427
+ NSLog(@"Rewarded ad failed to load with error: %@", [error localizedDescription]);
428
+ return;
429
+ }
430
+ self.rewardedAd = ad;
431
+ NSLog(@"Rewarded ad loaded.");
432
+ self.rewardedAd.fullScreenContentDelegate = self;
433
+ [self fireEvent:@"" event:@"on.rewarded.loaded" withData:nil];
434
+ }];
435
+ }
436
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
437
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
438
+ }
439
+ -(void)showRewardedAd:(CDVInvokedUrlCommand *)command {
440
+ CDVPluginResult *pluginResult;
441
+ NSString *callbackId = command.callbackId;
442
+ if (self.rewardedAd && [self.rewardedAd canPresentFromRootViewController:self.viewController error:nil]) {
443
+
444
+ [self.rewardedAd presentFromRootViewController:self.viewController
445
+ userDidEarnRewardHandler:^{
446
+ GADAdReward *reward =
447
+ self.rewardedAd.adReward;
448
+ [self fireEvent:@"" event:@"on.reward.userEarnedReward" withData:nil];
449
+
450
+ NSString *rewardMessage = [NSString stringWithFormat:@"Reward received with currency %@ , amount %lf", reward.type, [reward.amount doubleValue]];
451
+ NSLog(@"%@", rewardMessage);
452
+
453
+ }];
454
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
455
+ } else {
456
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
457
+ [self fireEvent:@"" event:@"on.rewarded.failed.show" withData:nil];
458
+ }
459
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId];
460
+ }
461
+ - (void) fireEvent:(NSString *)obj event:(NSString *)eventName withData:(NSString *)jsonStr {
462
+ NSString* js;
463
+ if(obj && [obj isEqualToString:@"window"]) {
464
+ js = [NSString stringWithFormat:@"var evt=document.createEvent(\"UIEvents\");evt.initUIEvent(\"%@\",true,false,window,0);window.dispatchEvent(evt);", eventName];
465
+ } else if(jsonStr && [jsonStr length]>0) {
466
+ js = [NSString stringWithFormat:@"javascript:cordova.fireDocumentEvent('%@',%@);", eventName, jsonStr];
467
+ } else {
468
+ js = [NSString stringWithFormat:@"javascript:cordova.fireDocumentEvent('%@');", eventName];
469
+ }
470
+ [self.commandDelegate evalJs:js];
471
+ }
472
+ #pragma mark GADBannerViewDelegate implementation
473
+ - (void)bannerViewDidReceiveAd:(GADBannerView *)bannerView {
474
+ [self fireEvent:@"" event:@"on.banner.load" withData:nil];
475
+ NSLog(@"bannerViewDidReceiveAd");
476
+ }
477
+ - (void)bannerView:(GADBannerView *)bannerView didFailToReceiveAdWithError:(NSError *)error {
478
+ [self fireEvent:@"" event:@"on.banner.failed.load" withData:nil];
479
+ NSLog(@"bannerView:didFailToReceiveAdWithError: %@", [error localizedDescription]);
480
+ }
481
+ - (void)bannerViewDidRecordImpression:(GADBannerView *)bannerView {
482
+ [self fireEvent:@"" event:@"on.banner.impression" withData:nil];
483
+ NSLog(@"bannerViewDidRecordImpression");
484
+ }
485
+ - (void)bannerViewWillPresentScreen:(GADBannerView *)bannerView {
486
+ [self fireEvent:@"" event:@"on.banner.open" withData:nil];
487
+ NSLog(@"bannerViewWillPresentScreen");
488
+ }
489
+ - (void)bannerViewWillDismissScreen:(GADBannerView *)bannerView {
490
+ [self fireEvent:@"" event:@"on.banner.close" withData:nil];
491
+ NSLog(@"bannerViewWillDismissScreen");
492
+ }
493
+ - (void)bannerViewDidDismissScreen:(GADBannerView *)bannerView {
494
+ [self fireEvent:@"" event:@"on.banner.did.dismiss" withData:nil];
495
+ NSLog(@"bannerViewDidDismissScreen");
496
+ }
497
+ #pragma GADFullScreeContentDelegate implementation
498
+ - (void)adWillPresentFullScreenContent:(id)ad {
499
+ if (adFormat == 1){
500
+ [self fireEvent:@"" event:@"on.appOpenAd.show" withData:nil];
501
+ NSLog(@"Ad will present full screen content App Open Ad.");
502
+ } else if (adFormat == 2){
503
+
504
+ [self fireEvent:@"" event:@"on.interstitial.show" withData:nil];
505
+ [self fireEvent:@"" event:@"onPresentAd" withData:nil];
506
+ NSLog(@"Ad will present full screen content interstitial.");
507
+ } else if (adFormat == 3) {
508
+ [self fireEvent:@"" event:@"on.rewarded.show" withData:nil];
509
+ NSLog(@"Ad will present full screen content rewarded.");
510
+ } else if (adFormat == 4) {
511
+ [self fireEvent:@"" event:@"on.rewardedInt.showed" withData:nil];
512
+ NSLog(@"Ad will present full screen content interstitial rewarded.");
513
+ }
514
+ }
515
+ - (void)ad:(id)ad didFailToPresentFullScreenContentWithError:(NSError *)error {
516
+ if (adFormat == 1){
517
+ [self fireEvent:@"" event:@"on.appOpenAd.failed.loaded" withData:nil];
518
+ NSLog(@"Ad failed to present full screen content with error App Open Ad %@.", [error localizedDescription]);
519
+ } else if (adFormat == 2){
520
+ [self fireEvent:@"" event:@"on.interstitial.failed.load" withData:nil];
521
+ NSLog(@"Ad failed to present full screen content with error interstitial %@.", [error localizedDescription]);
522
+ } else if (adFormat == 3) {
523
+ [self fireEvent:@"" event:@"on.rewarded.failed.load" withData:nil];
524
+ NSLog(@"Ad failed to present full screen content with error rewarded %@.", [error localizedDescription]);
525
+ } else if (adFormat == 4) {
526
+ [self fireEvent:@"" event:@"on.rewardedInt.failed.load" withData:nil];
527
+ NSLog(@"Ad failed to present full screen content with error interstitial rewarded %@.", [error localizedDescription]);
528
+ }
529
+ }
530
+ - (void)adDidDismissFullScreenContent:(id)ad {
531
+ if (adFormat == 1){
532
+ [self fireEvent:@"" event:@"on.appOpenAd.dismissed" withData:nil];
533
+ NSLog(@"Ad did dismiss full screen content App Open Ad.");
534
+ } else if (adFormat == 2){
535
+ [self fireEvent:@"" event:@"on.interstitial.dismissed" withData:nil];
536
+ NSLog(@"Ad did dismiss full screen content interstitial.");
537
+ } else if (adFormat == 3) {
538
+ [self fireEvent:@"" event:@"on.rewarded.dismissed" withData:nil];
539
+ NSLog(@"Ad did dismiss full screen content rewarded.");
540
+ } else if (adFormat == 4) {
541
+ [self fireEvent:@"" event:@"on.rewardedInt.dismissed" withData:nil];
542
+ NSLog(@"Ad did dismiss full screen content interstitial rewarded.");
543
+ }
544
+ }
545
+ #pragma mark Cleanup
546
+ - (void)dealloc {
547
+ self.appOpenAd = nil;
548
+ self.bannerView = nil;
549
+ self.interstitial = nil;
550
+ self.rewardedAd = nil;
551
+ self.rewardedInterstitialAd = nil;
552
+ }
553
+ @end
554
+
@@ -4,16 +4,8 @@ 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
-
15
- exports.loadAppOpenAd = function (arg0, arg1, arg2, success, error) {
16
- exec(success, error, 'emiAdmobPlugin', 'loadAppOpenAd', [arg0, arg1, arg2]);
7
+ exports.loadAppOpenAd = function (arg0, arg1, success, error) {
8
+ exec(success, error, 'emiAdmobPlugin', 'loadAppOpenAd', [arg0, arg1]);
17
9
  };
18
10
 
19
11
  exports.showAppOpenAd = function (success, error) {
@@ -32,24 +24,28 @@ exports.removeBannerAd = function (arg0, success, error) {
32
24
  exec(success, error, 'emiAdmobPlugin', 'removeBannerAd', [arg0]);
33
25
  };
34
26
 
35
- exports.loadInterstitialAd = function (arg0, arg1, arg2, success, error) {
36
- exec(success, error, 'emiAdmobPlugin', 'loadInterstitialAd', [arg0, arg1, arg2]);
27
+ exports.hideBannerAd = function (success, error) {
28
+ exec(success, error, 'emiAdmobPlugin', 'hideBannerAd', []);
29
+ };
30
+
31
+ exports.loadInterstitialAd = function (arg0, arg1, success, error) {
32
+ exec(success, error, 'emiAdmobPlugin', 'loadInterstitialAd', [arg0, arg1]);
37
33
  };
38
34
 
39
35
  exports.showInterstitialAd = function (success, error) {
40
36
  exec(success, error, 'emiAdmobPlugin', 'showInterstitialAd', []);
41
37
  };
42
38
 
43
- exports.loadRewardedAd = function (arg0, arg1, arg2, success, error) {
44
- exec(success, error, 'emiAdmobPlugin', 'loadRewardedAd', [arg0, arg1, arg2]);
39
+ exports.loadRewardedAd = function (arg0, arg1, success, error) {
40
+ exec(success, error, 'emiAdmobPlugin', 'loadRewardedAd', [arg0, arg1]);
45
41
  };
46
42
 
47
43
  exports.showRewardedAd = function (success, error) {
48
44
  exec(success, error, 'emiAdmobPlugin', 'showRewardedAd', []);
49
45
  };
50
46
 
51
- exports.loadRewardedInterstitialAd = function (arg0, arg1, arg2, success, error) {
52
- exec(success, error, 'emiAdmobPlugin', 'loadRewardedInterstitialAd', [arg0, arg1, arg2]);
47
+ exports.loadRewardedInterstitialAd = function (arg0, arg1, success, error) {
48
+ exec(success, error, 'emiAdmobPlugin', 'loadRewardedInterstitialAd', [arg0, arg1]);
53
49
  };
54
50
 
55
51
  exports.showRewardedInterstitialAd = function (success, error) {
@@ -68,6 +64,6 @@ exports.targeting = function (arg0, arg1, arg2, success, error) {
68
64
  exec(success, error, 'emiAdmobPlugin', 'targeting', [arg0, arg1, arg2]);
69
65
  };
70
66
 
71
- exports.globalSettings = function (arg0, arg1, arg2, success, error) {
72
- exec(success, error, 'emiAdmobPlugin', 'globalSettings', [arg0, arg1, arg2]);
67
+ exports.globalSettings = function (arg0, arg1, arg2, arg3, arg4, arg5, success, error) {
68
+ exec(success, error, 'emiAdmobPlugin', 'globalSettings', [arg0, arg1, arg2, arg3, arg4, arg5]);
73
69
  };
@@ -1,286 +0,0 @@
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
- }