@@ -3,11 +3,11 @@ import Capacitor
33import GoogleMobileAds
44
55class BannerExecutor : NSObject , GADBannerViewDelegate {
6- public weak var plugin : CAPPlugin ?
6+ public weak var plugin : AdMob ?
77 var bannerView : GADBannerView !
88
99 func showBanner( _ call: CAPPluginCall , _ request: GADRequest , _ adUnitID: String ) {
10- if let rootViewController = UIApplication . shared . keyWindow ? . rootViewController {
10+ if let rootViewController = plugin ? . getRootVC ( ) {
1111
1212 let adSize = call. getString ( " adSize " ) ?? " ADAPTIVE_BANNER "
1313 let adPosition = call. getString ( " position " ) ?? " BOTTOM_CENTER "
@@ -53,7 +53,7 @@ class BannerExecutor: NSObject, GADBannerViewDelegate {
5353 self . addBannerViewToView ( self . bannerView, adPosition, adMargin)
5454 self . bannerView. translatesAutoresizingMaskIntoConstraints = false
5555 self . bannerView. adUnitID = adUnitID
56- self . bannerView. rootViewController = UIApplication . shared . keyWindow ? . rootViewController
56+ self . bannerView. rootViewController = plugin ? . getRootVC ( )
5757
5858 self . bannerView. load ( request)
5959 self . bannerView. delegate = self
@@ -64,7 +64,7 @@ class BannerExecutor: NSObject, GADBannerViewDelegate {
6464
6565 func hideBanner( _ call: CAPPluginCall ) {
6666 DispatchQueue . main. async {
67- if let rootViewController = UIApplication . shared . keyWindow ? . rootViewController {
67+ if let rootViewController = self . plugin ? . getRootVC ( ) {
6868 if let subView = rootViewController. view. viewWithTag ( 2743243288699 ) {
6969 NSLog ( " AdMob: find subView for hideBanner " )
7070 subView. isHidden = true
@@ -83,7 +83,7 @@ class BannerExecutor: NSObject, GADBannerViewDelegate {
8383 }
8484
8585 func resumeBanner( _ call: CAPPluginCall ) {
86- if let rootViewController = UIApplication . shared . keyWindow ? . rootViewController {
86+ if let rootViewController = plugin ? . getRootVC ( ) {
8787 if let subView = rootViewController. view. viewWithTag ( 2743243288699 ) {
8888 NSLog ( " AdMob: find subView for resumeBanner " )
8989 subView. isHidden = false
@@ -109,7 +109,7 @@ class BannerExecutor: NSObject, GADBannerViewDelegate {
109109
110110 private func addBannerViewToView( _ bannerView: GADBannerView , _ adPosition: String , _ Margin: Int ) {
111111 removeBannerViewToView ( )
112- if let rootViewController = UIApplication . shared . keyWindow ? . rootViewController {
112+ if let rootViewController = plugin ? . getRootVC ( ) {
113113
114114 bannerView. translatesAutoresizingMaskIntoConstraints = false
115115 bannerView. tag = 2743243288699 // rand
@@ -134,7 +134,7 @@ class BannerExecutor: NSObject, GADBannerViewDelegate {
134134 }
135135
136136 private func removeBannerViewToView( ) {
137- if let rootViewController = UIApplication . shared . keyWindow ? . rootViewController {
137+ if let rootViewController = plugin ? . getRootVC ( ) {
138138 if let subView = rootViewController. view. viewWithTag ( 2743243288699 ) {
139139 bannerView. delegate = nil
140140 NSLog ( " AdMob: find subView " )
0 commit comments