emi-indo-cordova-plugin-admob 2.0.2 → 2.0.4

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.
@@ -17,6 +17,10 @@
17
17
 
18
18
  <p> <button onclick="loadAppOpen();">Auto Show App Open Ad</button></p>
19
19
 
20
+ <p> <button onclick="loadBanner();">load a show Banner Ad</button></p>
21
+ <p> <button onclick="showBanner();">show Banner Ad</button></p>
22
+ <p> <button onclick="hideBanner();">hide Banner Ad</button></p>
23
+ <p> <button onclick="removeBanner();">remove Banner Ad</button></p>
20
24
 
21
25
  <p> <button onclick="loadInterstitial();">Load Interstitial Ad</button></p>
22
26
  <p> <button onclick="showInterstitial();">Show Interstitial Ad</button></p>
@@ -10,16 +10,16 @@ function loadBanner() {
10
10
 
11
11
  if (typeof cordova !== 'undefined') {
12
12
 
13
- if (!isPlatformIOS){
14
-
13
+
15
14
  cordova.plugins.emiAdmobPlugin.styleBannerAd({
16
- isOverlapping: true,
17
- overlappingHeight: 0, // default 0 (Automatic)
18
- padding: 0, // default 0
19
- margins: 0 // default 0 (Automatic)
15
+ isOverlapping: true, // default false IOS | Android
16
+ isStatusBarShow: true, // default true Only Android
17
+ paddingWebView: 1.0, // Only IOS > padding banner Container and webView Container
18
+ overlappingHeight: 0, // default 0 (Automatic) Only Android
19
+ padding: 0, // default 0 Only Android
20
+ margins: 0 // default 0 (Automatic) Only Android
20
21
  });
21
22
 
22
- }
23
23
 
24
24
 
25
25
  cordova.plugins.emiAdmobPlugin.loadBannerAd({
@@ -37,6 +37,30 @@ function loadBanner() {
37
37
 
38
38
 
39
39
 
40
+ function showBanner() {
41
+
42
+ if (typeof cordova !== 'undefined') {
43
+ cordova.plugins.emiAdmobPlugin.showBannerAd();
44
+ }
45
+
46
+ }
47
+
48
+ function hideBanner() {
49
+
50
+ if (typeof cordova !== 'undefined') {
51
+ cordova.plugins.emiAdmobPlugin.hideBannerAd();
52
+ }
53
+
54
+ }
55
+
56
+
57
+ function removeBanner() {
58
+
59
+ if (typeof cordova !== 'undefined') {
60
+ cordova.plugins.emiAdmobPlugin.removeBannerAd();
61
+ }
62
+
63
+ }
40
64
 
41
65
 
42
66
  /* ///////<<<< bannerAd position >>>>>>\\\\\\\
@@ -83,11 +83,14 @@ document.addEventListener("deviceready", function () {
83
83
  }
84
84
 
85
85
 
86
- // (Optional) deactivate Google's consent
86
+ // (Optional)
87
87
  /*
88
88
  cordova.plugins.emiAdmobPlugin.metaData({
89
89
 
90
- useCustomConsentManager: false // Default false only android
90
+ useCustomConsentManager: false, // deactivate Google's consent Default false only android
91
+
92
+ isEnabledKeyword: false, // Default false only android
93
+ setKeyword: "" // https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob/discussions/54
91
94
 
92
95
  });
93
96
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emi-indo-cordova-plugin-admob",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
4
4
  "description": "Cordova/Quasar/Capacitor Plugin Admob Android IOS",
5
5
  "cordova": {
6
6
  "id": "emi-indo-cordova-plugin-admob",
package/plugin.xml CHANGED
@@ -1,6 +1,6 @@
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="2.0.2">
3
+ id="emi-indo-cordova-plugin-admob" version="2.0.4">
4
4
 
5
5
  <name>emiAdmobPlugin</name>
6
6
  <description>Cordova/Quasar/Capacitor Plugin Admob Android IOS</description>
@@ -51,8 +51,6 @@
51
51
  android:value="$APP_ID_ANDROID" />
52
52
  <meta-data android:name="com.google.android.gms.ads.DELAY_APP_MEASUREMENT_INIT"
53
53
  android:value="true" />
54
- <meta-data android:name="com.google.android.gms.ads.flag.OPTIMIZE_INITIALIZATION"
55
- android:value="false" />
56
54
  <meta-data android:name="com.google.android.gms.ads.flag.OPTIMIZE_AD_LOADING"
57
55
  android:value="true" />
58
56
  <meta-data
@@ -99,7 +97,7 @@
99
97
 
100
98
  <config-file parent="/*" target="config.xml">
101
99
  <!--minimum deployment-target: 12.2 -->
102
- <preference name="deployment-target" value="12.3" />
100
+ <preference name="deployment-target" value="13.0" />
103
101
  <preference name="SwiftVersion" value="5.10" />
104
102
  </config-file>
105
103
 
@@ -93,6 +93,7 @@ class emiAdmobPlugin : CordovaPlugin() {
93
93
 
94
94
  private var isOverlapping: Boolean = false
95
95
  private var overlappingHeight: Int = 0
96
+ private var isStatusBarShow: Boolean = true
96
97
 
97
98
  var adType = ""
98
99
 
@@ -143,6 +144,8 @@ class emiAdmobPlugin : CordovaPlugin() {
143
144
  private var isUsingAdManagerRequest = false
144
145
 
145
146
  private var isCustomConsentManager = false
147
+ private var isEnabledKeyword: Boolean = false
148
+ private var setKeyword: String = ""
146
149
 
147
150
  private var mActivity: Activity? = null
148
151
  private var mContext: Context? = null
@@ -1135,56 +1138,59 @@ class emiAdmobPlugin : CordovaPlugin() {
1135
1138
  } else if (action == "styleBannerAd") {
1136
1139
  val options = args.getJSONObject(0)
1137
1140
  if (mActivity != null) {
1138
- mActivity?.runOnUiThread {
1139
- val screenHeight: Int
1140
- val usableHeight: Int
1141
-
1142
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
1143
- val windowMetrics = cordova.activity.windowManager.currentWindowMetrics
1144
- val insets = windowMetrics.windowInsets.getInsetsIgnoringVisibility(WindowInsets.Type.navigationBars())
1145
- screenHeight = windowMetrics.bounds.height()
1146
- usableHeight = screenHeight - insets.bottom
1147
- } else {
1148
- val display = cordova.activity.windowManager.defaultDisplay
1149
- val size = Point()
1150
- val realSize = Point()
1151
- display.getSize(size)
1152
- display.getRealSize(realSize)
1153
-
1154
- usableHeight = size.y
1155
- screenHeight = realSize.y
1156
- }
1157
1141
 
1158
- val navBarHeight = maxOf(0, screenHeight - usableHeight)
1142
+ val screenHeight: Int
1143
+ val usableHeight: Int
1144
+
1145
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
1146
+ val windowMetrics = cordova.activity.windowManager.currentWindowMetrics
1147
+ val insets = windowMetrics.windowInsets.getInsetsIgnoringVisibility(WindowInsets.Type.navigationBars())
1148
+ screenHeight = windowMetrics.bounds.height()
1149
+ usableHeight = screenHeight - insets.bottom
1150
+ } else {
1151
+ val display = cordova.activity.windowManager.defaultDisplay
1152
+ val size = Point()
1153
+ val realSize = Point()
1154
+ display.getSize(size)
1155
+ display.getRealSize(realSize)
1156
+
1157
+ usableHeight = size.y
1158
+ screenHeight = realSize.y
1159
+ }
1160
+
1161
+ val navBarHeight = maxOf(0, screenHeight - usableHeight)
1162
+
1163
+ val isOverlapping = options.optBoolean("isOverlapping", false)
1164
+ val setStatusBarShow = options.optBoolean("isStatusBarShow", true)
1165
+ val overlappingHeight = options.optInt("overlappingHeight", navBarHeight)
1166
+ val paddingPx = options.optInt("padding", 0)
1167
+ val marginsPx = options.optInt("margins", navBarHeight)
1159
1168
 
1160
- val isOverlapping = options.optBoolean("isOverlapping", false)
1161
- val overlappingHeight = options.optInt("overlappingHeight", navBarHeight)
1162
- val paddingPx = options.optInt("padding", 0)
1163
- val marginsPx = options.optInt("margins", navBarHeight)
1169
+ this.isOverlapping = isOverlapping
1170
+ this.isStatusBarShow = setStatusBarShow
1171
+ this.overlappingHeight = if (overlappingHeight > 0) overlappingHeight else navBarHeight
1172
+ this.paddingInPx = paddingPx
1173
+ this.marginsInPx = if (marginsPx > 0) marginsPx else navBarHeight
1174
+
1175
+ cordova.getThreadPool().execute {
1164
1176
 
1165
- val result = JSONObject()
1166
1177
  try {
1167
- // Make sure to only set variables if they have the correct values
1168
- this.isOverlapping = isOverlapping
1169
- this.overlappingHeight = if (overlappingHeight > 0) overlappingHeight else navBarHeight
1170
- this.paddingInPx = paddingPx
1171
- this.marginsInPx = if (marginsPx > 0) marginsPx else navBarHeight
1172
-
1173
- // Add more useful data to the result
1174
- result.put("navBarHeight", navBarHeight)
1175
- result.put("screenHeight", screenHeight)
1176
- result.put("usableHeight", usableHeight)
1177
- result.put("isOverlapping", isOverlapping)
1178
- result.put("overlappingHeight", this.overlappingHeight)
1179
- result.put("paddingInPx", paddingPx)
1180
- result.put("marginsInPx", this.marginsInPx)
1181
-
1182
- cWebView?.let {
1183
- it.loadUrl("javascript:cordova.fireDocumentEvent('on.style.banner.ad', ${result});")
1184
- } ?: run {
1185
- callbackContext.error("Error: cWebView is null.")
1186
- }
1187
1178
 
1179
+ val eventData = """
1180
+ {
1181
+ "navBarHeight": "$navBarHeight",
1182
+ "screenHeight": "$screenHeight",
1183
+ "usableHeight": "$usableHeight",
1184
+ "isOverlapping": $isOverlapping,
1185
+ "overlappingHeight": "$overlappingHeight",
1186
+ "paddingInPx": "$paddingPx",
1187
+ "marginsInPx": "$marginsInPx"
1188
+ }
1189
+ """.trimIndent()
1190
+
1191
+ mActivity?.runOnUiThread {
1192
+ cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.style.banner.ad', $eventData)")
1193
+ }
1188
1194
  } catch (e: Exception) {
1189
1195
  callbackContext.error("Error in styleBannerAd: ${e.message}")
1190
1196
  }
@@ -1195,8 +1201,12 @@ class emiAdmobPlugin : CordovaPlugin() {
1195
1201
  } else if (action == "metaData") {
1196
1202
  val options = args.getJSONObject(0)
1197
1203
  val useCustomConsentManager = options.optBoolean("useCustomConsentManager")
1204
+ val useCustomKeyword = options.optBoolean("isEnabledKeyword")
1205
+ val keywordValue = options.optString("setKeyword")
1198
1206
  if (mActivity != null) {
1199
1207
  this.isCustomConsentManager = useCustomConsentManager
1208
+ this.isEnabledKeyword = useCustomKeyword
1209
+ this.setKeyword = keywordValue
1200
1210
  }
1201
1211
  return true
1202
1212
  } else if (action == "hideBannerAd") {
@@ -1607,55 +1617,58 @@ class emiAdmobPlugin : CordovaPlugin() {
1607
1617
 
1608
1618
 
1609
1619
 
1610
- private fun bannerOverlapping() {
1611
- if (bannerView != null && mActivity != null && cWebView != null) {
1612
- mActivity?.runOnUiThread {
1613
- try {
1614
-
1615
- val displayMetrics = DisplayMetrics()
1616
- mActivity?.windowManager?.defaultDisplay?.getMetrics(displayMetrics)
1617
- val screenHeightInPx = displayMetrics.heightPixels
1618
-
1619
- val webViewHeight = screenHeightInPx - (adSize.height + overlappingHeight)
1620
- val layoutParams = cWebView?.view?.layoutParams
1621
- layoutParams?.height = webViewHeight
1622
- cWebView?.view?.layoutParams = layoutParams
1623
-
1624
- // Log.d("BannerAdjustment", "Adjusted WebView height: $webViewHeight")
1625
- } catch (e: Exception) {
1626
- Log.e("AdmobPlugin", "Error adjusting WebView for banner: ${e.message}")
1620
+ private fun bannerOverlapping() {
1621
+ if (bannerView != null && mActivity != null && cWebView != null) {
1622
+ mActivity?.runOnUiThread {
1623
+ try {
1624
+ val displayMetrics = DisplayMetrics()
1625
+ mActivity!!.windowManager.defaultDisplay.getMetrics(displayMetrics)
1626
+ val screenHeightInPx = displayMetrics.heightPixels
1627
+
1628
+ val webViewHeight = if (isStatusBarShow) {
1629
+ screenHeightInPx - (adSize.height + overlappingHeight)
1630
+ } else {
1631
+ screenHeightInPx + (adSize.height + overlappingHeight)
1627
1632
  }
1633
+ val layoutParams = cWebView!!.view.layoutParams
1634
+ layoutParams.height = webViewHeight
1635
+ cWebView!!.view.layoutParams = layoutParams
1636
+
1637
+ // Log.d("BannerAdjustment", "Adjusted WebView height: $webViewHeight")
1638
+ } catch (e: Exception) {
1639
+ Log.e("AdmobPlugin", "Error adjusting WebView for banner: ${e.message}")
1628
1640
  }
1629
1641
  }
1630
1642
  }
1643
+ }
1631
1644
 
1632
1645
 
1633
1646
 
1634
-
1635
-
1636
-
1637
-
1638
- private val bannerPaidAdListener = OnPaidEventListener { adValue ->
1639
- val valueMicros = adValue.valueMicros.takeIf { it > 0 } ?: 0L
1640
- val currencyCode = adValue.currencyCode.ifBlank { "UNKNOWN" }
1641
- val precision = adValue.precisionType.takeIf { it >= 0 } ?: AdValue.PrecisionType.UNKNOWN
1642
- val adUnitId = bannerView?.adUnitId ?: "null"
1643
- val result = JSONObject()
1644
- try {
1645
- result.put("micros", valueMicros)
1646
- result.put("currency", currencyCode)
1647
- result.put("precision", precision)
1648
- result.put("adUnitId", adUnitId)
1649
- isBannerLoad = false
1650
- isBannerShow = true
1651
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.banner.revenue', ${result});")
1652
- } catch (e: JSONException) {
1653
- PUBLIC_CALLBACKS!!.error(e.message)
1647
+ private val bannerPaidAdListener = OnPaidEventListener { adValue ->
1648
+ val valueMicros = adValue.valueMicros.takeIf { it > 0 } ?: 0L
1649
+ val currencyCode = adValue.currencyCode.ifBlank { "UNKNOWN" }
1650
+ val precision = adValue.precisionType.takeIf { it >= 0 } ?: AdValue.PrecisionType.UNKNOWN
1651
+ val adUnitId = bannerView?.adUnitId ?: "null"
1652
+ val result = JSONObject()
1653
+ try {
1654
+ result.put("micros", valueMicros)
1655
+ result.put("currency", currencyCode)
1656
+ result.put("precision", precision)
1657
+ result.put("adUnitId", adUnitId)
1658
+ isBannerLoad = false
1659
+ isBannerShow = true
1660
+ cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.banner.revenue', ${result});")
1661
+ } catch (e: JSONException) {
1662
+ PUBLIC_CALLBACKS!!.error(e.message)
1663
+ }
1654
1664
  }
1655
- }
1656
-
1657
1665
 
1658
1666
  private fun setBannerSize(size: String?) {
1667
+ if (mActivity == null || bannerView == null) {
1668
+ Log.e("AdBanner", "mActivity or bannerView is null. Cannot set banner size.")
1669
+ return
1670
+ }
1671
+
1659
1672
  when (size) {
1660
1673
  "responsive_adaptive" -> bannerView?.setAdSize(adSize)
1661
1674
  "anchored_adaptive" -> bannerView?.setAdSize(
@@ -1663,41 +1676,42 @@ class emiAdmobPlugin : CordovaPlugin() {
1663
1676
  mActivity!!, adWidth
1664
1677
  )
1665
1678
  )
1666
-
1667
1679
  "full_width_adaptive" -> bannerView?.setAdSize(
1668
1680
  AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(
1669
1681
  mActivity!!, adWidth
1670
1682
  )
1671
1683
  )
1672
-
1673
1684
  "in_line_adaptive" -> bannerView?.setAdSize(
1674
1685
  AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize(
1675
1686
  mActivity!!, adWidth
1676
1687
  )
1677
1688
  )
1678
-
1679
1689
  "banner" -> bannerView?.setAdSize(AdSize.BANNER)
1680
1690
  "large_banner" -> bannerView?.setAdSize(AdSize.LARGE_BANNER)
1681
1691
  "medium_rectangle" -> bannerView?.setAdSize(AdSize.MEDIUM_RECTANGLE)
1682
1692
  "full_banner" -> bannerView?.setAdSize(AdSize.FULL_BANNER)
1683
1693
  "leaderboard" -> bannerView?.setAdSize(AdSize.LEADERBOARD)
1684
1694
  "fluid" -> bannerView?.setAdSize(AdSize.FLUID)
1695
+ else -> Log.e("AdBanner", "Unknown banner size: $size")
1685
1696
  }
1686
1697
  }
1687
1698
 
1688
-
1689
1699
  private val adSize: AdSize
1690
1700
  get() {
1691
- val outMetrics = DisplayMetrics()
1701
+ if (mActivity == null) {
1702
+ throw IllegalStateException("mActivity is null. Cannot get adSize.")
1703
+ }
1692
1704
 
1705
+ val outMetrics = DisplayMetrics()
1693
1706
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
1694
- val windowMetrics = mActivity!!.windowManager.currentWindowMetrics
1695
- val insets = windowMetrics.windowInsets
1696
- .getInsetsIgnoringVisibility(WindowInsets.Type.systemBars())
1697
- val bounds = windowMetrics.bounds
1698
- val widthPixels = bounds.width() - insets.left - insets.right
1699
- outMetrics.widthPixels = widthPixels
1700
- outMetrics.density = mActivity!!.resources.displayMetrics.density
1707
+ mActivity?.windowManager?.currentWindowMetrics?.let { windowMetrics ->
1708
+ val insets = windowMetrics.windowInsets
1709
+ .getInsetsIgnoringVisibility(WindowInsets.Type.systemBars())
1710
+ val bounds = windowMetrics.bounds
1711
+ val widthPixels = bounds.width() - insets.left - insets.right
1712
+ outMetrics.widthPixels = widthPixels
1713
+ outMetrics.density = mActivity!!.resources.displayMetrics.density
1714
+ }
1701
1715
  } else {
1702
1716
  @Suppress("DEPRECATION")
1703
1717
  mActivity?.windowManager?.defaultDisplay?.getMetrics(outMetrics)
@@ -1705,37 +1719,39 @@ class emiAdmobPlugin : CordovaPlugin() {
1705
1719
 
1706
1720
  val density = outMetrics.density
1707
1721
  val adWidthPixels =
1708
- if (bannerViewLayout != null && bannerViewLayout!!.width > 0) bannerViewLayout!!.width else outMetrics.widthPixels
1722
+ if ((bannerViewLayout?.width ?: 0) > 0) bannerViewLayout!!.width else outMetrics.widthPixels
1709
1723
  val adWidth = (adWidthPixels / density).toInt()
1710
1724
  return AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(mActivity!!, adWidth)
1711
1725
  }
1712
1726
 
1713
-
1714
1727
  private val adWidth: Int
1715
1728
  get() {
1716
- val outMetrics = DisplayMetrics()
1729
+ if (mActivity == null) {
1730
+ throw IllegalStateException("mActivity is null. Cannot calculate adWidth.")
1731
+ }
1717
1732
 
1733
+ val outMetrics = DisplayMetrics()
1718
1734
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
1719
- val windowMetrics = mActivity!!.windowManager.currentWindowMetrics
1720
- val insets = windowMetrics.windowInsets
1721
- .getInsetsIgnoringVisibility(WindowInsets.Type.systemBars())
1722
- val bounds = windowMetrics.bounds
1723
- val widthPixels = bounds.width() - insets.left - insets.right
1724
- outMetrics.widthPixels = widthPixels
1725
- outMetrics.density = mActivity!!.resources.displayMetrics.density
1735
+ mActivity?.windowManager?.currentWindowMetrics?.let { windowMetrics ->
1736
+ val insets = windowMetrics.windowInsets
1737
+ .getInsetsIgnoringVisibility(WindowInsets.Type.systemBars())
1738
+ val bounds = windowMetrics.bounds
1739
+ val widthPixels = bounds.width() - insets.left - insets.right
1740
+ outMetrics.widthPixels = widthPixels
1741
+ outMetrics.density = mActivity!!.resources.displayMetrics.density
1742
+ }
1726
1743
  } else {
1727
1744
  @Suppress("DEPRECATION")
1728
- mActivity!!.windowManager.defaultDisplay.getMetrics(outMetrics)
1745
+ mActivity?.windowManager?.defaultDisplay?.getMetrics(outMetrics)
1729
1746
  }
1730
1747
 
1731
1748
  val density = outMetrics.density
1732
1749
  val adWidthPixels =
1733
- (if (bannerViewLayout != null && bannerViewLayout!!.width > 0) bannerViewLayout!!.width else outMetrics.widthPixels).toFloat()
1750
+ (bannerViewLayout?.width?.takeIf { it > 0 } ?: outMetrics.widthPixels).toFloat()
1734
1751
  return (adWidthPixels / density).toInt()
1735
1752
  }
1736
1753
 
1737
1754
 
1738
-
1739
1755
  private fun handleConsentForm() {
1740
1756
  if(mActivity != null) {
1741
1757
  if (consentInformation!!.isConsentFormAvailable) {
@@ -1929,6 +1945,11 @@ class emiAdmobPlugin : CordovaPlugin() {
1929
1945
  }
1930
1946
  }
1931
1947
 
1948
+ if (isEnabledKeyword) {
1949
+ setKeyword.split(",").forEach { keyword ->
1950
+ builder.addKeyword(keyword.trim())
1951
+ }
1952
+ }
1932
1953
 
1933
1954
  val bundleExtra = Bundle()
1934
1955
  // bundleExtra.putString("npa", this.Npa); DEPRECATED Beginning January 16, 2024
@@ -1963,6 +1984,13 @@ class emiAdmobPlugin : CordovaPlugin() {
1963
1984
  if (isCollapsible) {
1964
1985
  bundleExtra.putString("collapsible", this.collapsiblePos)
1965
1986
  }
1987
+
1988
+ if (isEnabledKeyword) {
1989
+ setKeyword.split(",").forEach { keyword ->
1990
+ builder.addKeyword(keyword.trim())
1991
+ }
1992
+ }
1993
+
1966
1994
  bundleExtra.putBoolean("is_designed_for_families", this.isSetTagForChildDirectedTreatment)
1967
1995
  bundleExtra.putBoolean("under_age_of_consent", this.isSetTagForUnderAgeOfConsent)
1968
1996
  bundleExtra.putString("max_ad_content_rating", this.isSetMaxAdContentRating)
@@ -2235,6 +2263,7 @@ class emiAdmobPlugin : CordovaPlugin() {
2235
2263
  }
2236
2264
 
2237
2265
 
2266
+
2238
2267
  private val view: View?
2239
2268
  get() {
2240
2269
  if (View::class.java.isAssignableFrom(CordovaWebView::class.java)) {
@@ -17,6 +17,8 @@
17
17
  @property (nonatomic, assign) BOOL isUsingAdManagerRequest;
18
18
  @property (nonatomic, assign) CGFloat viewWidth;
19
19
  @property (nonatomic, strong) UIView *bannerViewLayout;
20
+ @property (nonatomic, strong) UIView *bannerContainer;
21
+ @property (nonatomic, strong) UIView *webViewContainer;
20
22
 
21
23
  - (void)initialize:(CDVInvokedUrlCommand *)command;
22
24
  - (void)requestIDFA:(CDVInvokedUrlCommand *)command;
@@ -26,6 +28,7 @@
26
28
  - (void)getIabTfc:(CDVInvokedUrlCommand *)command;
27
29
  - (void)loadAppOpenAd:(CDVInvokedUrlCommand *)command;
28
30
  - (void)showAppOpenAd:(CDVInvokedUrlCommand *)command;
31
+ - (void)styleBannerAd:(CDVInvokedUrlCommand *)command;
29
32
  - (void)loadBannerAd:(CDVInvokedUrlCommand *)command;
30
33
  - (void)showBannerAd:(CDVInvokedUrlCommand *)command;
31
34
  - (void)hideBannerAd:(CDVInvokedUrlCommand *)command;
@@ -38,3 +41,4 @@
38
41
  - (void)showRewardedAd:(CDVInvokedUrlCommand *)command;
39
42
  - (void) fireEvent:(NSString *)obj event:(NSString *)eventName withData:(NSString *)jsonStr;
40
43
  @end
44
+
@@ -4,6 +4,7 @@
4
4
  #import <Cordova/CDVPlugin.h>
5
5
  #import <Foundation/Foundation.h>
6
6
  #import <UserMessagingPlatform/UserMessagingPlatform.h>
7
+ #import <Cordova/CDVViewController.h>
7
8
  @implementation emiAdmobPlugin
8
9
  @synthesize appOpenAd;
9
10
  @synthesize bannerView;
@@ -18,6 +19,7 @@ int attStatus = 0;
18
19
  int Consent_Status = 0;
19
20
  int adFormat = 0;
20
21
  int adWidth = 320; // Default
22
+
21
23
  BOOL auto_Show = NO;
22
24
  // NSString *Npa = @"1"; // Deprecated
23
25
  NSString *setPosition = @"bottom-center"; // Default
@@ -26,6 +28,11 @@ NSString *bannerSaveAdUnitId = @""; // autoResize dependency = true
26
28
  BOOL isCollapsible = NO;
27
29
  BOOL isAutoResize = NO;
28
30
 
31
+
32
+ CGFloat paddingWebView = 0; // Default
33
+ BOOL isSetOverlapping = NO; // Default
34
+ CGFloat bannerHeightFinal = 50; // Default
35
+
29
36
  int isAdSkip = 0;
30
37
  BOOL UnderAgeOfConsent = NO;
31
38
  BOOL isPrivacyOptions = NO;
@@ -33,6 +40,7 @@ BOOL isDebugGeography = NO;
33
40
  BOOL isResponseInfo = NO;
34
41
  BOOL isUsingAdManagerRequest = YES;
35
42
 
43
+
36
44
  - (BOOL)canRequestAds {
37
45
  return UMPConsentInformation.sharedInstance.canRequestAds;
38
46
  }
@@ -259,7 +267,7 @@ BOOL isUsingAdManagerRequest = YES;
259
267
  } else {
260
268
  [UMPConsentForm presentPrivacyOptionsFormFromViewController:self.viewController completionHandler:^(NSError *_Nullable formError) {
261
269
  if (formError) {
262
- // NSLog(@"Error when displaying the form: %@", formError);
270
+ NSLog(@"Error when displaying the form: %@", formError);
263
271
  }
264
272
  }];
265
273
  }
@@ -324,8 +332,7 @@ BOOL isUsingAdManagerRequest = YES;
324
332
 
325
333
  - (BOOL)isPrivacyOptionsRequired {
326
334
  UMPPrivacyOptionsRequirementStatus status = UMPConsentInformation.sharedInstance.privacyOptionsRequirementStatus;
327
- // NSLog(@"[isPrivacyOptionsRequired] Privacy option status: %ld",
328
- // (long)status);
335
+
329
336
  return status == UMPPrivacyOptionsRequirementStatusRequired;
330
337
  }
331
338
 
@@ -347,9 +354,6 @@ BOOL isUsingAdManagerRequest = YES;
347
354
  Consent_Status = UMPConsentStatusObtained;
348
355
  }
349
356
 
350
- /* NSLog(@"The Consent "
351
- @"Status %i",
352
- Consent_Status); */
353
357
  CDVPluginResult *pluginResult =
354
358
  [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
355
359
  messageAsInt:Consent_Status];
@@ -448,7 +452,7 @@ BOOL isUsingAdManagerRequest = YES;
448
452
  requestConfiguration.maxAdContentRating =
449
453
  GADMaxAdContentRatingMatureAudience;
450
454
  } else {
451
- // NSLog(@"Unknown content rating: %@", contentRating);
455
+ NSLog(@"Unknown content rating: %@", contentRating);
452
456
  }
453
457
  }
454
458
 
@@ -538,9 +542,7 @@ BOOL isUsingAdManagerRequest = YES;
538
542
  [self.bannerViewLayout bringSubviewToFront:self.bannerView];
539
543
 
540
544
  } @catch (NSException *exception) {
541
- // NSLog(@"Error adjusting banner size: %@", exception.reason);
542
- // PUBLIC_CALLBACKS.error([NSString stringWithFormat:@"Error adjusting
543
- // banner size: %@", exception.reason]);
545
+ // banner size: %@", exception.reason]);
544
546
  }
545
547
  });
546
548
  }
@@ -631,37 +633,12 @@ BOOL isUsingAdManagerRequest = YES;
631
633
 
632
634
 
633
635
 
634
- - (GADAdSize)__AdSizeFromString:(NSString *)size {
635
-
636
- if (self.viewWidth == 0) {
637
- self.viewWidth = [UIScreen mainScreen].bounds.size.width;
638
- }
639
-
640
- if ([size isEqualToString:@"responsive_adaptive"]) {
641
- return GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(
642
- self.viewWidth);
643
- } else if ([size isEqualToString:@"in_line_adaptive"]) {
644
- return GADCurrentOrientationInlineAdaptiveBannerAdSizeWithWidth(
645
- self.viewWidth);
646
- } else if ([size isEqualToString:@"banner"]) {
647
- return GADAdSizeBanner;
648
- } else if ([size isEqualToString:@"large_banner"]) {
649
- return GADAdSizeLargeBanner;
650
- } else if ([size isEqualToString:@"full_banner"]) {
651
- return GADAdSizeFullBanner;
652
- } else if ([size isEqualToString:@"leaderboard"]) {
653
- return GADAdSizeLeaderboard;
654
- } else {
655
- return GADAdSizeBanner;
656
- }
657
- }
658
-
659
636
  - (void)showBannerAd:(CDVInvokedUrlCommand *)command {
660
637
  CDVPluginResult *pluginResult;
661
638
  NSString *callbackId = command.callbackId;
662
639
  if (self.bannerView) {
663
640
  self.bannerView.hidden = NO;
664
- [self addBannerViewToView:command];
641
+ [self addBannerViewToView:command];
665
642
  pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
666
643
  } else {
667
644
  [self fireEvent:@"" event:@"on.banner.failed.show" withData:nil];
@@ -730,13 +707,162 @@ BOOL isUsingAdManagerRequest = YES;
730
707
  constant:0]
731
708
  ]];
732
709
  }
710
+ [self bannerOverlapping];
733
711
  }
712
+
713
+
714
+
715
+
716
+
717
+ - (void)bannerOverlapping {
718
+ if (!self.bannerView || !self.webView) {
719
+ NSLog(@"[AdPlugin] Error: Missing bannerView or webView. Adjustment skipped.");
720
+ return;
721
+ }
722
+
723
+ if (isSetOverlapping){
724
+
725
+ dispatch_async(dispatch_get_main_queue(), ^{
726
+ @try {
727
+
728
+ CGFloat screenWidth = UIScreen.mainScreen.bounds.size.width;
729
+ CGFloat screenHeight = UIScreen.mainScreen.bounds.size.height;
730
+
731
+ CGFloat navigationBarHeight = 0.0;
732
+ if (@available(iOS 11.0, *)) {
733
+ navigationBarHeight = self.viewController.view.safeAreaInsets.bottom;
734
+ }
735
+
736
+ if (!self.bannerContainer) {
737
+ self.bannerContainer = [[UIView alloc] initWithFrame:CGRectZero];
738
+ // self.bannerContainer.backgroundColor = [UIColor redColor]; // Debug
739
+ [self.viewController.view addSubview:self.bannerContainer];
740
+ }
741
+
742
+ if (!self.webViewContainer) {
743
+ self.webViewContainer = [[UIView alloc] initWithFrame:CGRectZero];
744
+ // self.webViewContainer.backgroundColor = [UIColor blueColor]; // Debug
745
+ [self.viewController.view addSubview:self.webViewContainer];
746
+ }
747
+
748
+ CGRect bannerContainerFrame = CGRectZero;
749
+ if ([setPosition isEqualToString:@"top-center"]) {
750
+ bannerContainerFrame = CGRectMake(0, 0, screenWidth, bannerHeightFinal);
751
+ } else if ([setPosition isEqualToString:@"bottom-center"]) {
752
+ bannerContainerFrame = CGRectMake(0, screenHeight - paddingWebView - bannerHeightFinal - navigationBarHeight, screenWidth, bannerHeightFinal);
753
+ }
754
+ self.bannerContainer.frame = bannerContainerFrame;
755
+
756
+ self.bannerView.frame = self.bannerContainer.bounds;
757
+ [self.bannerContainer addSubview:self.bannerView];
758
+
759
+ CGRect webViewContainerFrame = CGRectZero;
760
+ if ([setPosition isEqualToString:@"top-center"]) {
761
+ webViewContainerFrame = CGRectMake(0, bannerHeightFinal, screenWidth, screenHeight - bannerHeightFinal);
762
+ } else if ([setPosition isEqualToString:@"bottom-center"]) {
763
+
764
+ webViewContainerFrame = CGRectMake(0, 0, screenWidth, screenHeight - bannerHeightFinal - paddingWebView - navigationBarHeight);
765
+
766
+ }
767
+ self.webViewContainer.frame = webViewContainerFrame;
768
+
769
+ self.webView.frame = self.webViewContainer.bounds;
770
+ [self.webViewContainer addSubview:self.webView];
771
+
772
+ [self.bannerContainer setNeedsLayout];
773
+ [self.bannerContainer layoutIfNeeded];
774
+ [self.webViewContainer setNeedsLayout];
775
+ [self.webViewContainer layoutIfNeeded];
776
+
777
+
778
+ NSLog(@"[AdPlugin] Banner and WebView are now in separate containers with proper sizing.");
779
+ } @catch (NSException *exception) {
780
+ NSLog(@"[AdPlugin] Error adjusting layout for banner and WebView: %@", exception.reason);
781
+ }
782
+
783
+ });
784
+ }
785
+ }
786
+
787
+
788
+
789
+
790
+
791
+ - (void)styleBannerAd:(CDVInvokedUrlCommand *)command {
792
+
793
+ NSDictionary *options = [command.arguments objectAtIndex:0];
794
+ BOOL isOverlapping = [[options valueForKey:@"isOverlapping"] boolValue];
795
+ CGFloat paddingContainer = [[options valueForKey:@"paddingWebView"] floatValue];
796
+
797
+ isSetOverlapping = isOverlapping;
798
+ paddingWebView = paddingContainer;
799
+
800
+ }
801
+
802
+
803
+ - (GADAdSize)__AdSizeFromString:(NSString *)size {
804
+
805
+ if (self.viewWidth == 0) {
806
+ self.viewWidth = [UIScreen mainScreen].bounds.size.width;
807
+ }
808
+
809
+ if ([size isEqualToString:@"responsive_adaptive"]) {
810
+ return GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(
811
+ self.viewWidth);
812
+ } else if ([size isEqualToString:@"in_line_adaptive"]) {
813
+ return GADCurrentOrientationInlineAdaptiveBannerAdSizeWithWidth(
814
+ self.viewWidth);
815
+ } else if ([size isEqualToString:@"banner"]) {
816
+ return GADAdSizeBanner;
817
+ } else if ([size isEqualToString:@"large_banner"]) {
818
+ return GADAdSizeLargeBanner;
819
+ } else if ([size isEqualToString:@"full_banner"]) {
820
+ return GADAdSizeFullBanner;
821
+ } else if ([size isEqualToString:@"leaderboard"]) {
822
+ return GADAdSizeLeaderboard;
823
+ } else {
824
+ return GADAdSizeBanner;
825
+ }
826
+ }
827
+
828
+
829
+
830
+
831
+
832
+
833
+ - (void)resetWebViewHeight {
834
+ if (!self.webView) {
835
+ NSLog(@"[AdPlugin] Error: WebView is missing. Reset skipped.");
836
+ return;
837
+ }
838
+
839
+ dispatch_async(dispatch_get_main_queue(), ^{
840
+ @try {
841
+
842
+ CGFloat screenHeightInPx = UIScreen.mainScreen.bounds.size.height;
843
+
844
+ CGRect webViewFrame = self.webView.frame;
845
+ webViewFrame.size.height = screenHeightInPx;
846
+ self.webView.frame = webViewFrame;
847
+
848
+ [self.webView setNeedsLayout];
849
+ [self.webView layoutIfNeeded];
850
+
851
+ } @catch (NSException *exception) {
852
+ NSLog(@"[AdPlugin] Error resetting WebView height: %@", exception.reason);
853
+ }
854
+ });
855
+ }
856
+
857
+
858
+
734
859
  - (void)hideBannerAd:(CDVInvokedUrlCommand *)command {
735
860
  CDVPluginResult *pluginResult;
736
861
  NSString *callbackId = command.callbackId;
737
862
  if (self.bannerView) {
738
863
  dispatch_async(dispatch_get_main_queue(), ^{
739
864
  self.bannerView.hidden = YES;
865
+ [self resetWebViewHeight];
740
866
  [self fireEvent:@"" event:@"on.banner.hide" withData:nil];
741
867
  });
742
868
  pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
@@ -753,6 +879,7 @@ BOOL isUsingAdManagerRequest = YES;
753
879
  self.bannerView.hidden = YES;
754
880
  [self.bannerView removeFromSuperview];
755
881
  self.bannerView = nil;
882
+ [self resetWebViewHeight];
756
883
  [self fireEvent:@"" event:@"on.banner.remove" withData:nil];
757
884
  });
758
885
  pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
@@ -1436,6 +1563,15 @@ BOOL isUsingAdManagerRequest = YES;
1436
1563
  return hexString;
1437
1564
  }
1438
1565
 
1566
+
1567
+
1568
+
1569
+
1570
+
1571
+
1572
+
1573
+
1574
+
1439
1575
  #pragma mark GADBannerViewDelegate implementation
1440
1576
 
1441
1577
  - (void)bannerViewDidReceiveAd:(GADBannerView *)bannerView {
@@ -1452,9 +1588,9 @@ BOOL isUsingAdManagerRequest = YES;
1452
1588
 
1453
1589
  // Get the banner height
1454
1590
  CGFloat bannerHeight = bannerView.bounds.size.height;
1591
+ bannerHeightFinal = bannerHeight;
1455
1592
 
1456
1593
 
1457
-
1458
1594
  // Prepare height data for banner load event
1459
1595
  NSDictionary *bannerLoadData = @{@"height" : @(bannerHeight)};
1460
1596
  NSData *bannerLoadJsonData = [NSJSONSerialization dataWithJSONObject:bannerLoadData options:0 error:&error];
@@ -1465,7 +1601,7 @@ BOOL isUsingAdManagerRequest = YES;
1465
1601
 
1466
1602
  if (auto_Show && self.bannerView) {
1467
1603
  [self addBannerViewToView:command];
1468
- self.bannerView.hidden = NO;
1604
+ [self showBannerAd:command];
1469
1605
  } else {
1470
1606
  [self fireEvent:@"" event:@"on.banner.failed.show" withData:nil];
1471
1607
  }