Skip to content

Commit 1e0ba0b

Browse files
committed
Merge branch 'master' of github.com:capacitor-community/admob
2 parents 3fb8265 + f2c60fb commit 1e0ba0b

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ios/Sources/AdMobPlugin/AdMobPlugin.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ public class AdMobPlugin: CAPPlugin, CAPBridgedPlugin {
2525
CAPPluginMethod(name: "prepareInterstitial", returnType: CAPPluginReturnPromise),
2626
CAPPluginMethod(name: "showInterstitial", returnType: CAPPluginReturnPromise),
2727
CAPPluginMethod(name: "prepareRewardVideoAd", returnType: CAPPluginReturnPromise),
28-
CAPPluginMethod(name: "showRewardVideoAd", returnType: CAPPluginReturnPromise)
28+
CAPPluginMethod(name: "showRewardVideoAd", returnType: CAPPluginReturnPromise),
29+
CAPPluginMethod(name: "prepareRewardInterstitialAd", returnType: CAPPluginReturnPromise),
30+
CAPPluginMethod(name: "showRewardInterstitialAd", returnType: CAPPluginReturnPromise)
2931
]
3032

3133
var testingDevices: [String] = []

ios/Sources/AdMobPlugin/Banner/BannerExecutor.swift

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import GoogleMobileAds
55
class BannerExecutor: NSObject, BannerViewDelegate {
66
weak var plugin: AdMobPlugin?
77
var bannerView: BannerView!
8+
var adPosition: String = ""
9+
var Margin: Int = 0
810

911
func showBanner(_ call: CAPPluginCall, _ request: Request, _ adUnitID: String) {
1012
if let rootViewController = plugin?.getRootVC() {
@@ -109,20 +111,36 @@ class BannerExecutor: NSObject, BannerViewDelegate {
109111

110112
private func addBannerViewToView(_ bannerView: BannerView, _ adPosition: String, _ Margin: Int) {
111113
removeBannerViewToView()
114+
bannerView.translatesAutoresizingMaskIntoConstraints = false
115+
bannerView.tag = 2743243288699 // rand
116+
self.Margin = Margin
117+
self.adPosition = adPosition
118+
}
119+
120+
private func removeBannerViewToView() {
112121
if let rootViewController = plugin?.getRootVC() {
122+
if let subView = rootViewController.view.viewWithTag(2743243288699) {
123+
bannerView.delegate = nil
124+
NSLog("AdMob: find subView")
125+
subView.removeFromSuperview()
126+
}
127+
}
128+
}
113129

114-
bannerView.translatesAutoresizingMaskIntoConstraints = false
115-
bannerView.tag = 2743243288699 // rand
130+
/// Tells the delegate an ad request loaded an ad.
131+
func bannerViewDidReceiveAd(_ bannerView: GADBannerView) {
132+
NSLog("bannerViewDidReceiveAd")
133+
if let rootViewController = plugin?.getRootVC() {
116134
rootViewController.view.addSubview(bannerView)
117135
rootViewController.view.addConstraints(
118136
[NSLayoutConstraint(item: bannerView,
119-
attribute: adPosition == "TOP_CENTER" ? .top : .bottom,
137+
attribute: self.adPosition == "TOP_CENTER" ? .top : .bottom,
120138
relatedBy: .equal,
121139
toItem: rootViewController.view.safeAreaLayoutGuide,
122-
attribute: adPosition == "TOP_CENTER" ? .top : .bottom,
140+
attribute: self.adPosition == "TOP_CENTER" ? .top : .bottom,
123141
multiplier: 1,
124-
constant: CGFloat(Int(Margin) * -1)),
125-
NSLayoutConstraint(item: bannerView,
142+
constant: CGFloat(Int(self.Margin) * -1)),
143+
NSLayoutConstraint(item: bannerView,
126144
attribute: .centerX,
127145
relatedBy: .equal,
128146
toItem: rootViewController.view,

0 commit comments

Comments
 (0)