Skip to content

Commit

Permalink
Add Ad Inspector support.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 662977413
  • Loading branch information
JillSong authored and copybara-github committed Aug 22, 2024
1 parent 7a55f59 commit 88e80cc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="22154" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" colorMatched="YES" initialViewController="etj-Oz-3ZH">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="32700.99.1234" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" colorMatched="YES" initialViewController="etj-Oz-3ZH">
<device id="retina5_9" orientation="portrait" appearance="light"/>
<dependencies>
<deployment version="2304" identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22130"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22684"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand Down Expand Up @@ -56,6 +56,11 @@
</view>
<toolbarItems/>
<navigationItem key="navigationItem" id="hLj-GS-7ye">
<barButtonItem key="leftBarButtonItem" title="Ad Inspector" id="WVj-zR-fCx" userLabel="Ad Inspector Button">
<connections>
<action selector="adInspectorTapped:" destination="BYZ-38-t0r" id="dmq-6D-WuG"/>
</connections>
</barButtonItem>
<barButtonItem key="rightBarButtonItem" enabled="NO" title="Privacy Settings" id="NwL-0f-yie">
<connections>
<action selector="privacySettingsTapped:" destination="BYZ-38-t0r" id="3L6-ZF-LLQ"/>
Expand All @@ -64,6 +69,7 @@
</navigationItem>
<nil key="simulatedBottomBarMetrics"/>
<connections>
<outlet property="adInspectorButton" destination="WVj-zR-fCx" id="hgI-s6-jKZ"/>
<outlet property="bannerView" destination="b5b-Tm-bLe" id="uyc-7n-h89"/>
<outlet property="privacySettingsButton" destination="NwL-0f-yie" id="O4c-sy-9qm"/>
</connections>
Expand Down
20 changes: 18 additions & 2 deletions Swift/admob/BannerExample/BannerExample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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 }
Expand Down

0 comments on commit 88e80cc

Please sign in to comment.