Skip to content

Commit fa28f0f

Browse files
Add a more generic helper
1 parent 0f7ca22 commit fa28f0f

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

TeadsDemoApp.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
B502BA171F8282DB008257EC /* TeadsAdTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B502BA161F8282DB008257EC /* TeadsAdTableViewCell.swift */; };
1616
B502BA191F836D3E008257EC /* WebViewEmbededInScrollViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B502BA181F836D3E008257EC /* WebViewEmbededInScrollViewController.swift */; };
1717
B50C184922CCDC65004F2360 /* AdMobInWebViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B50C184822CCDC65004F2360 /* AdMobInWebViewController.swift */; };
18-
B50C184D22CCDF49004F2360 /* SyncWebViewGoogleAdView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B50C184B22CCDF49004F2360 /* SyncWebViewGoogleAdView.swift */; };
18+
B50C184D22CCDF49004F2360 /* SyncWebViewAdView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B50C184B22CCDF49004F2360 /* SyncWebViewAdView.swift */; };
1919
B52842262213284A00025E97 /* SyncWebViewTFInReadAdView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B52842252213284A00025E97 /* SyncWebViewTFInReadAdView.swift */; };
2020
B5555A361F7CDF80007406D4 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5555A351F7CDF80007406D4 /* AppDelegate.swift */; };
2121
B5555A381F7CDF80007406D4 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5555A371F7CDF80007406D4 /* ViewController.swift */; };
@@ -53,7 +53,7 @@
5353
B502BA161F8282DB008257EC /* TeadsAdTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TeadsAdTableViewCell.swift; sourceTree = "<group>"; };
5454
B502BA181F836D3E008257EC /* WebViewEmbededInScrollViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebViewEmbededInScrollViewController.swift; sourceTree = "<group>"; };
5555
B50C184822CCDC65004F2360 /* AdMobInWebViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdMobInWebViewController.swift; sourceTree = "<group>"; };
56-
B50C184B22CCDF49004F2360 /* SyncWebViewGoogleAdView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SyncWebViewGoogleAdView.swift; sourceTree = "<group>"; };
56+
B50C184B22CCDF49004F2360 /* SyncWebViewAdView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SyncWebViewAdView.swift; sourceTree = "<group>"; };
5757
B52842252213284A00025E97 /* SyncWebViewTFInReadAdView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SyncWebViewTFInReadAdView.swift; path = TeadsDemoApp/Controllers/webViewController/webViewHelper/SyncWebViewTFInReadAdView.swift; sourceTree = SOURCE_ROOT; };
5858
B5555A321F7CDF80007406D4 /* TeadsDemoApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TeadsDemoApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
5959
B5555A351F7CDF80007406D4 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
@@ -208,7 +208,7 @@
208208
B50C184A22CCDF35004F2360 /* WebViewHelper */ = {
209209
isa = PBXGroup;
210210
children = (
211-
B50C184B22CCDF49004F2360 /* SyncWebViewGoogleAdView.swift */,
211+
B50C184B22CCDF49004F2360 /* SyncWebViewAdView.swift */,
212212
);
213213
path = WebViewHelper;
214214
sourceTree = "<group>";
@@ -446,7 +446,7 @@
446446
B5CCB65F1FB20D8C00BA4B72 /* TeadsAdCollectionViewCell.swift in Sources */,
447447
B561029F1F84C3DD00E59C76 /* WebViewEmbededCollectionViewController.swift in Sources */,
448448
B502BA191F836D3E008257EC /* WebViewEmbededInScrollViewController.swift in Sources */,
449-
B50C184D22CCDF49004F2360 /* SyncWebViewGoogleAdView.swift in Sources */,
449+
B50C184D22CCDF49004F2360 /* SyncWebViewAdView.swift in Sources */,
450450
B502BA131F827D5C008257EC /* TableViewController.swift in Sources */,
451451
B502BA171F8282DB008257EC /* TeadsAdTableViewCell.swift in Sources */,
452452
B57FB1F11FC5E21F00609036 /* PidTableViewCell.swift in Sources */,

TeadsDemoApp/Controllers/adMobController/AdMobInWebViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import TeadsAdMobAdapter
1313
class AdMobInWebViewController: UIViewController, WKNavigationDelegate, GADBannerViewDelegate {
1414

1515
@IBOutlet weak var webView: WKWebView!
16-
var webSync: SyncWebViewGoogleAdView!
16+
var webSync: SyncWebViewAdView!
1717
var bannerView: GADBannerView!
1818

1919
// FIXME This ids should be replaced by your own AdMob application and ad block/unit ids
@@ -47,7 +47,7 @@ class AdMobInWebViewController: UIViewController, WKNavigationDelegate, GADBanne
4747

4848
request.register(teadsExtras.getCustomEventExtras(forCustomEventLabel: "Teads"))
4949
self.bannerView.load(request)
50-
self.webSync = SyncWebViewGoogleAdView(webView: self.webView, selector: "#my-placement-id", admobBannerView: self.bannerView, bannerSize: kGADAdSizeMediumRectangle)
50+
self.webSync = SyncWebViewAdView(webView: self.webView, selector: "#my-placement-id", adView: self.bannerView)
5151
}
5252

5353
// MARK: - GADBannerViewDelegate Protocol
Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// SyncWebViewGoogleAdView.swift
2+
// SyncWebViewAdView.swift
33
// TeadsApp
44
//
55
// Created by Jérémy Grosjean on 20/05/2019.
@@ -11,20 +11,18 @@ import GoogleMobileAds
1111
import TeadsAdMobAdapter
1212
import WebKit
1313

14-
class SyncWebViewGoogleAdView: NSObject, WebViewHelperDelegate {
15-
14+
class SyncWebViewAdView: NSObject, WebViewHelperDelegate {
15+
1616
weak var webView: WKWebView?
17-
weak var admobBannerView: GADBannerView?
17+
weak var adView: UIView?
1818
var webViewHelper: WebViewHelper
1919
var isLoaded = false
2020
var adViewConstraints = [NSLayoutConstraint]()
21-
var bannerSize: GADAdSize
2221

23-
public init(webView: WKWebView, selector: String, admobBannerView: GADBannerView, bannerSize: GADAdSize) {
22+
public init(webView: WKWebView, selector: String, adView: UIView) {
2423
webViewHelper = WebViewHelper(webView: webView, selector: selector)
25-
self.admobBannerView = admobBannerView
24+
self.adView = adView
2625
self.webView = webView
27-
self.bannerSize = bannerSize
2826
super.init()
2927
webViewHelper.delegate = self
3028
}
@@ -63,7 +61,7 @@ class SyncWebViewGoogleAdView: NSObject, WebViewHelperDelegate {
6361

6462
public func webViewHelperUpdatedSlot(left: Int, top: Int, right: Int, bottom: Int) {
6563
// if the adView is not already loaded load it and add it to the scrollView of your webview
66-
if let admobBannerView = admobBannerView, let webView = webView {
64+
if let admobBannerView = adView, let webView = webView {
6765
if !isLoaded {
6866
isLoaded = true
6967
webView.scrollView.addSubview(admobBannerView)
@@ -76,7 +74,7 @@ class SyncWebViewGoogleAdView: NSObject, WebViewHelperDelegate {
7674

7775
/// change the constraint of the ad so it follows what the bootstrap ask
7876
func customAdViewConstraint(left: Int, top: Int, right: Int, bottom: Int) {
79-
if let admobBannerView = admobBannerView, let webView = webView {
77+
if let admobBannerView = adView, let webView = webView {
8078
NSLayoutConstraint.deactivate(adViewConstraints)
8179
adViewConstraints.removeAll()
8280
adViewConstraints.append(admobBannerView.leadingAnchor.constraint(equalTo: webView.scrollView.leadingAnchor, constant: CGFloat(left)))

0 commit comments

Comments
 (0)