diff --git a/Swift/admob/BannerExample/BannerExample/Base.lproj/Main.storyboard b/Swift/admob/BannerExample/BannerExample/Base.lproj/Main.storyboard index eb932808..ae91ad92 100644 --- a/Swift/admob/BannerExample/BannerExample/Base.lproj/Main.storyboard +++ b/Swift/admob/BannerExample/BannerExample/Base.lproj/Main.storyboard @@ -1,9 +1,9 @@ - + - + @@ -56,6 +56,11 @@ + + + + + @@ -64,6 +69,7 @@ + diff --git a/Swift/admob/BannerExample/BannerExample/ViewController.swift b/Swift/admob/BannerExample/BannerExample/ViewController.swift index 82d4bee7..e9844500 100644 --- a/Swift/admob/BannerExample/BannerExample/ViewController.swift +++ b/Swift/admob/BannerExample/BannerExample/ViewController.swift @@ -21,6 +21,7 @@ class ViewController: UIViewController, GADBannerViewDelegate { @IBOutlet weak var bannerView: GADBannerView! @IBOutlet weak var privacySettingsButton: UIBarButtonItem! + @IBOutlet weak var adInspectorButton: UIBarButtonItem! private var isMobileAdsStartCalled = false private var isViewDidAppearCalled = false @@ -76,10 +77,10 @@ class ViewController: UIViewController, GADBannerViewDelegate { }) } - // Handle changes to user consent. + /// Handle changes to user consent. @IBAction func privacySettingsTapped(_ sender: UIBarButtonItem) { GoogleMobileAdsConsentManager.shared.presentPrivacyOptionsForm(from: self) { - [weak self] (formError) in + [weak self] formError in guard let self, let formError else { return } let alertController = UIAlertController( @@ -90,6 +91,21 @@ class ViewController: UIViewController, GADBannerViewDelegate { } } + /// Handle ad inspector launch. + @IBAction func adInspectorTapped(_ sender: UIBarButtonItem) { + GADMobileAds.sharedInstance().presentAdInspector(from: self) { + // Error will be non-nil if there was an issue and the inspector was not displayed. + [weak self] error in + guard let self, let error else { return } + + let alertController = UIAlertController( + title: error.localizedDescription, message: "Please try again later.", + preferredStyle: .alert) + alertController.addAction(UIAlertAction(title: "OK", style: .cancel)) + self.present(alertController, animated: true) + } + } + private func startGoogleMobileAdsSDK() { DispatchQueue.main.async { guard !self.isMobileAdsStartCalled else { return }