Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated examples Podfile.lock to use version 7.54.0 of the SDK. #143

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

maddevrelgithubbot
Copy link
Contributor

Updated examples Podfile.lock to use version 7.54.0 of the SDK.

@Sachinbarole
Copy link

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())

}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants