@capacitor-community/admob 4.0.0-1 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CapacitorCommunityAdmob.podspec +1 -1
- package/README.md +8 -16
- package/android/build.gradle +5 -2
- package/ios/Plugin/Banner/BannerExecutor.swift +7 -7
- package/ios/Plugin/Interstitial/AdInterstitialExecutor.swift +3 -3
- package/ios/Plugin/Plugin.swift +13 -0
- package/ios/Plugin/Rewarded/AdRewardExecutor.swift +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -46,33 +46,19 @@ Made with [contributors-img](https://contrib.rocks).
|
|
|
46
46
|
If you use capacitor 4:
|
|
47
47
|
|
|
48
48
|
```
|
|
49
|
-
% npm install --save @capacitor-community/admob@
|
|
49
|
+
% npm install --save @capacitor-community/admob@latest
|
|
50
50
|
% npx cap update
|
|
51
51
|
```
|
|
52
52
|
|
|
53
53
|
capacitor 3:
|
|
54
54
|
|
|
55
55
|
```
|
|
56
|
-
% npm install --save @capacitor-community/admob
|
|
56
|
+
% npm install --save @capacitor-community/admob@3.3.0
|
|
57
57
|
% npx cap update
|
|
58
58
|
```
|
|
59
59
|
|
|
60
60
|
### Android configuration
|
|
61
61
|
|
|
62
|
-
In file `android/app/src/main/java/**/**/MainActivity.java`, add the plugin to the initialization list:
|
|
63
|
-
|
|
64
|
-
```java
|
|
65
|
-
import android.os.Bundle;
|
|
66
|
-
|
|
67
|
-
public class MainActivity extends BridgeActivity {
|
|
68
|
-
@Override
|
|
69
|
-
public void onCreate(Bundle savedInstanceState) {
|
|
70
|
-
super.onCreate(savedInstanceState);
|
|
71
|
-
registerPlugin(com.getcapacitor.community.admob.AdMob.class);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
```
|
|
75
|
-
|
|
76
62
|
In file `android/app/src/main/AndroidManifest.xml`, add the following XML elements under `<manifest><application>` :
|
|
77
63
|
|
|
78
64
|
```xml
|
|
@@ -89,6 +75,12 @@ In file `android/app/src/main/res/values/strings.xml` add the following lines :
|
|
|
89
75
|
|
|
90
76
|
Don't forget to replace `[APP_ID]` by your AdMob application Id.
|
|
91
77
|
|
|
78
|
+
#### Variables
|
|
79
|
+
|
|
80
|
+
This plugin will use the following project variables (defined in your app's `variables.gradle` file):
|
|
81
|
+
|
|
82
|
+
- `$playServicesAdsVersion` version of `com.google.android.gms:play-services-ads` (default: `21.1.0`)
|
|
83
|
+
|
|
92
84
|
### iOS configuration
|
|
93
85
|
|
|
94
86
|
Add the following in the `ios/App/App/info.plist` file inside of the outermost `<dict>`:
|
package/android/build.gradle
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
ext {
|
|
2
2
|
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
|
3
3
|
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.4.2'
|
|
4
|
+
androidxCoordinatorLayoutVersion = project.hasProperty('androidxCoordinatorLayoutVersion') ? rootProject.ext.androidxCoordinatorLayoutVersion : '1.2.0'
|
|
4
5
|
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.3'
|
|
5
6
|
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.4.0'
|
|
7
|
+
playServicesAdsVersion = project.hasProperty('playServicesAdsVersion') ? rootProject.ext.playServicesAdsVersion : '21.1.0'
|
|
8
|
+
|
|
6
9
|
}
|
|
7
10
|
|
|
8
11
|
buildscript {
|
|
@@ -72,9 +75,9 @@ dependencies {
|
|
|
72
75
|
// androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
73
76
|
|
|
74
77
|
// after 20.5.0, require minCompileSdk (31)
|
|
75
|
-
implementation
|
|
78
|
+
implementation "com.google.android.gms:play-services-ads:$playServicesAdsVersion"
|
|
76
79
|
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
77
|
-
implementation "androidx.coordinatorlayout:coordinatorlayout
|
|
80
|
+
implementation "androidx.coordinatorlayout:coordinatorlayout:$androidxCoordinatorLayoutVersion"
|
|
78
81
|
implementation "androidx.core:core-ktx:1.6.0"
|
|
79
82
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
|
80
83
|
}
|
|
@@ -3,11 +3,11 @@ import Capacitor
|
|
|
3
3
|
import GoogleMobileAds
|
|
4
4
|
|
|
5
5
|
class BannerExecutor: NSObject, GADBannerViewDelegate {
|
|
6
|
-
public weak var plugin:
|
|
6
|
+
public weak var plugin: AdMob?
|
|
7
7
|
var bannerView: GADBannerView!
|
|
8
8
|
|
|
9
9
|
func showBanner(_ call: CAPPluginCall, _ request: GADRequest, _ adUnitID: String) {
|
|
10
|
-
if let rootViewController =
|
|
10
|
+
if let rootViewController = plugin?.getRootVC() {
|
|
11
11
|
|
|
12
12
|
let adSize = call.getString("adSize") ?? "ADAPTIVE_BANNER"
|
|
13
13
|
let adPosition = call.getString("position") ?? "BOTTOM_CENTER"
|
|
@@ -53,7 +53,7 @@ class BannerExecutor: NSObject, GADBannerViewDelegate {
|
|
|
53
53
|
self.addBannerViewToView(self.bannerView, adPosition, adMargin)
|
|
54
54
|
self.bannerView.translatesAutoresizingMaskIntoConstraints = false
|
|
55
55
|
self.bannerView.adUnitID = adUnitID
|
|
56
|
-
self.bannerView.rootViewController =
|
|
56
|
+
self.bannerView.rootViewController = plugin?.getRootVC()
|
|
57
57
|
|
|
58
58
|
self.bannerView.load(request)
|
|
59
59
|
self.bannerView.delegate = self
|
|
@@ -64,7 +64,7 @@ class BannerExecutor: NSObject, GADBannerViewDelegate {
|
|
|
64
64
|
|
|
65
65
|
func hideBanner(_ call: CAPPluginCall) {
|
|
66
66
|
DispatchQueue.main.async {
|
|
67
|
-
if let rootViewController =
|
|
67
|
+
if let rootViewController = self.plugin?.getRootVC() {
|
|
68
68
|
if let subView = rootViewController.view.viewWithTag(2743243288699) {
|
|
69
69
|
NSLog("AdMob: find subView for hideBanner")
|
|
70
70
|
subView.isHidden = true
|
|
@@ -83,7 +83,7 @@ class BannerExecutor: NSObject, GADBannerViewDelegate {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
func resumeBanner(_ call: CAPPluginCall) {
|
|
86
|
-
if let rootViewController =
|
|
86
|
+
if let rootViewController = plugin?.getRootVC() {
|
|
87
87
|
if let subView = rootViewController.view.viewWithTag(2743243288699) {
|
|
88
88
|
NSLog("AdMob: find subView for resumeBanner")
|
|
89
89
|
subView.isHidden = false
|
|
@@ -109,7 +109,7 @@ class BannerExecutor: NSObject, GADBannerViewDelegate {
|
|
|
109
109
|
|
|
110
110
|
private func addBannerViewToView(_ bannerView: GADBannerView, _ adPosition: String, _ Margin: Int) {
|
|
111
111
|
removeBannerViewToView()
|
|
112
|
-
if let rootViewController =
|
|
112
|
+
if let rootViewController = plugin?.getRootVC() {
|
|
113
113
|
|
|
114
114
|
bannerView.translatesAutoresizingMaskIntoConstraints = false
|
|
115
115
|
bannerView.tag = 2743243288699 // rand
|
|
@@ -134,7 +134,7 @@ class BannerExecutor: NSObject, GADBannerViewDelegate {
|
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
private func removeBannerViewToView() {
|
|
137
|
-
if let rootViewController =
|
|
137
|
+
if let rootViewController = plugin?.getRootVC() {
|
|
138
138
|
if let subView = rootViewController.view.viewWithTag(2743243288699) {
|
|
139
139
|
bannerView.delegate = nil
|
|
140
140
|
NSLog("AdMob: find subView")
|
|
@@ -3,7 +3,7 @@ import Capacitor
|
|
|
3
3
|
import GoogleMobileAds
|
|
4
4
|
|
|
5
5
|
class AdInterstitialExecutor: NSObject, GADFullScreenContentDelegate {
|
|
6
|
-
public weak var plugin:
|
|
6
|
+
public weak var plugin: AdMob?
|
|
7
7
|
var interstitial: GADInterstitialAd!
|
|
8
8
|
|
|
9
9
|
func prepareInterstitial(_ call: CAPPluginCall, _ request: GADRequest, _ adUnitID: String) {
|
|
@@ -32,7 +32,7 @@ class AdInterstitialExecutor: NSObject, GADFullScreenContentDelegate {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
func showInterstitial(_ call: CAPPluginCall) {
|
|
35
|
-
if let rootViewController =
|
|
35
|
+
if let rootViewController = plugin?.getRootVC() {
|
|
36
36
|
if let ad = self.interstitial {
|
|
37
37
|
ad.present(fromRootViewController: rootViewController)
|
|
38
38
|
call.resolve([:])
|
|
@@ -50,7 +50,7 @@ class AdInterstitialExecutor: NSObject, GADFullScreenContentDelegate {
|
|
|
50
50
|
"message": error.localizedDescription
|
|
51
51
|
])
|
|
52
52
|
}
|
|
53
|
-
|
|
53
|
+
|
|
54
54
|
public func adWillPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) {
|
|
55
55
|
NSLog("InterstitialFullScreenDelegate Ad did present full screen content.")
|
|
56
56
|
self.plugin?.notifyListeners(InterstitialAdPluginEvents.Showed.rawValue, data: [:])
|
package/ios/Plugin/Plugin.swift
CHANGED
|
@@ -201,4 +201,17 @@ public class AdMob: CAPPlugin {
|
|
|
201
201
|
}
|
|
202
202
|
|
|
203
203
|
}
|
|
204
|
+
|
|
205
|
+
func getRootVC() -> UIViewController? {
|
|
206
|
+
var window: UIWindow? = UIApplication.shared.delegate?.window ?? nil
|
|
207
|
+
|
|
208
|
+
if window == nil {
|
|
209
|
+
let scene: UIWindowScene? = UIApplication.shared.connectedScenes.first as? UIWindowScene
|
|
210
|
+
window = scene?.windows.filter({$0.isKeyWindow}).first
|
|
211
|
+
if window == nil {
|
|
212
|
+
window = scene?.windows.first
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return window?.rootViewController
|
|
216
|
+
}
|
|
204
217
|
}
|
|
@@ -3,7 +3,7 @@ import Capacitor
|
|
|
3
3
|
import GoogleMobileAds
|
|
4
4
|
|
|
5
5
|
class AdRewardExecutor: NSObject, GADFullScreenContentDelegate {
|
|
6
|
-
public weak var plugin:
|
|
6
|
+
public weak var plugin: AdMob?
|
|
7
7
|
var rewardedAd: GADRewardedAd!
|
|
8
8
|
|
|
9
9
|
func prepareRewardVideoAd(_ call: CAPPluginCall, _ request: GADRequest, _ adUnitID: String) {
|
|
@@ -49,7 +49,7 @@ class AdRewardExecutor: NSObject, GADFullScreenContentDelegate {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
func showRewardVideoAd(_ call: CAPPluginCall) {
|
|
52
|
-
if let rootViewController =
|
|
52
|
+
if let rootViewController = plugin?.getRootVC() {
|
|
53
53
|
if let ad = self.rewardedAd {
|
|
54
54
|
ad.present(fromRootViewController: rootViewController,
|
|
55
55
|
userDidEarnRewardHandler: {
|
|
@@ -71,7 +71,7 @@ class AdRewardExecutor: NSObject, GADFullScreenContentDelegate {
|
|
|
71
71
|
"message": error.localizedDescription
|
|
72
72
|
])
|
|
73
73
|
}
|
|
74
|
-
|
|
74
|
+
|
|
75
75
|
public func adWillPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) {
|
|
76
76
|
NSLog("RewardFullScreenDelegate Ad did present full screen content.")
|
|
77
77
|
self.plugin?.notifyListeners(RewardAdPluginEvents.Showed.rawValue, data: [:])
|