jenkins-ci
jenkins-ci copied to clipboard
Updated examples Podfile.lock to use version 7.54.0 of the SDK.
Updated examples Podfile.lock to use version 7.54.0 of the SDK.
class ViewController: UIViewController {
@IBOutlet weak var bannerView: GADBannerView!
override func viewDidLoad() { super.viewDidLoad()
// Step 1 - Create a GADBannerView (in code or interface builder) and set the
// ad unit ID on it.
bannerView.adUnitID = "ca-app-pub-3940256099942544/2435281174"
bannerView.rootViewController = self
}
override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) // Note loadBannerAd is called in viewDidAppear as this is the first time that // the safe area is known. If safe area is not a concern (e.g., your app is // locked in portrait mode), the banner can be loaded in viewWillAppear. loadBannerAd() }
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { super.viewWillTransition(to:size, with:coordinator) coordinator.animate(alongsideTransition: { _ in self.loadBannerAd() }) }
func loadBannerAd() { // Step 2 - Determine the view width to use for the ad width. let frame = { () -> CGRect in // Here safe area is taken into account, hence the view frame is used // after the view has been laid out. if #available(iOS 11.0, *) { return view.frame.inset(by: view.safeAreaInsets) } else { return view.frame } }() let viewWidth = frame.size.width
// Step 3 - Get Adaptive GADAdSize and set the ad view.
// Here the current interface orientation is used. If the ad is being preloaded
// for a future orientation change or different orientation, the function for the
// relevant orientation should be used.
bannerView.adSize = GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(viewWidth)
// Step 4 - Create an ad request and load the adaptive banner ad.
bannerView.load(GADRequest())
} }