Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions SmartAd/Classes/SmartAdBanner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public protocol SmartAdBannerDelegate: NSObjectProtocol {
}

public class SmartAdBanner: UIView {

@IBOutlet open weak var delegate: SmartAdBannerDelegate?

@IBInspectable public var adOrderString : String? {
Expand All @@ -34,6 +34,8 @@ public class SmartAdBanner: UIView {
fileprivate var gAdView : GADBannerView?
fileprivate var fAdView : FBAdView?

fileprivate var isGoogle = false

fileprivate lazy var rootController: UIViewController? = {
var responder: UIResponder? = self
while responder != nil {
Expand Down Expand Up @@ -73,6 +75,8 @@ public class SmartAdBanner: UIView {
gAdView.rootViewController = rootController
gAdView.adUnitID = gID
self <<== gAdView
self.bringSubviewToFront(gAdView)
self.layoutIfNeeded()
}
}

Expand All @@ -81,6 +85,8 @@ public class SmartAdBanner: UIView {
if let fAdView = fAdView {
fAdView.delegate = self
self <<== fAdView
self.bringSubviewToFront(fAdView)
self.layoutIfNeeded()
}
}

Expand All @@ -102,6 +108,7 @@ public class SmartAdBanner: UIView {
if isAutoHeight {
if let constraint = (constraints.filter{$0.firstAttribute == .height}.first) {
constraint.constant = adHeight
self.fAdView?.isHidden = isGoogle
}
}
delegate?.smartAdBannerDone(self)
Expand All @@ -120,6 +127,7 @@ public class SmartAdBanner: UIView {

extension SmartAdBanner: GADBannerViewDelegate {
public func adViewDidReceiveAd(_ bannerView: GADBannerView) {
self.isGoogle = true
onDone(adHeight: bannerView.adSize.size.height)
}

Expand All @@ -138,6 +146,7 @@ extension SmartAdBanner: GADBannerViewDelegate {

extension SmartAdBanner: FBAdViewDelegate {
public func adViewDidLoad(_ adView: FBAdView) {
self.isGoogle = false
onDone(adHeight: fbAdSize.size.height)
}

Expand All @@ -153,4 +162,3 @@ extension SmartAdBanner: FBAdViewDelegate {
}
}
}