Skip to content

Commit 8699b7e

Browse files
author
Artsem Lemiasheuski
committed
Do not show Ads if there is no internet.
1 parent ce809d7 commit 8699b7e

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

OpenDocumentReader/DocumentViewController.swift

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import Firebase
1313
import GoogleMobileAds
1414

1515
// taken from: https://developer.apple.com/documentation/uikit/view_controllers/building_a_document_browser-based_app
16-
class DocumentViewController: UIViewController, DocumentDelegate {
16+
class DocumentViewController: UIViewController, DocumentDelegate, GADBannerViewDelegate {
1717

1818
private var browserTransition: DocumentBrowserTransitioningDelegate?
1919
public var transitionController: UIDocumentBrowserTransitionController? {
@@ -64,6 +64,7 @@ class DocumentViewController: UIViewController, DocumentDelegate {
6464

6565
document?.webview = self.webview
6666

67+
bannerView.delegate = self
6768
bannerView.adUnitID = "ca-app-pub-3940256099942544/2934735716"
6869
bannerView.rootViewController = self
6970

@@ -84,11 +85,19 @@ class DocumentViewController: UIViewController, DocumentDelegate {
8485
bannerView.adSize = GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(viewWidth)
8586
bannerView.load(GADRequest())
8687
} else {
87-
bannerView.isHidden = true
88-
bannerViewHeight.constant = 0.0
88+
hideBannerView()
8989
}
9090
}
91+
92+
func hideBannerView() {
93+
bannerView.isHidden = true
94+
bannerViewHeight.constant = 0.0
95+
}
9196

97+
func adView(_ bannerView: GADBannerView, didFailToReceiveAdWithError error: GADRequestError) {
98+
hideBannerView()
99+
}
100+
92101
override func viewDidAppear(_ animated: Bool) {
93102
super.viewDidAppear(animated)
94103
}

0 commit comments

Comments
 (0)