@@ -5,6 +5,8 @@ import GoogleMobileAds
55class 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