Skip to content

Commit d54f9ef

Browse files
malandr2copybara-github
authored andcommitted
Moved viewWillTransitionToSize code to Snippets
PiperOrigin-RevId: 801003069
1 parent 408646f commit d54f9ef

File tree

6 files changed

+19
-44
lines changed

6 files changed

+19
-44
lines changed

Objective-C/admanager/AdManagerBannerExample/AdManagerBannerExample/ViewController.m

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -115,18 +115,6 @@ - (void)viewDidLoad {
115115
}
116116
}
117117

118-
- (void)viewWillTransitionToSize:(CGSize)size
119-
withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
120-
[coordinator
121-
animateAlongsideTransition:^(
122-
id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
123-
if (GoogleMobileAdsConsentManager.sharedInstance.canRequestAds) {
124-
[self loadBannerAd];
125-
}
126-
}
127-
completion:nil];
128-
}
129-
130118
- (void)startGoogleMobileAdsSDK {
131119
static dispatch_once_t onceToken;
132120
dispatch_once(&onceToken, ^{

Objective-C/admob/BannerExample/BannerExample/ViewController.m

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -115,18 +115,6 @@ - (void)viewDidLoad {
115115
}
116116
}
117117

118-
- (void)viewWillTransitionToSize:(CGSize)size
119-
withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
120-
[coordinator
121-
animateAlongsideTransition:^(
122-
id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
123-
if (GoogleMobileAdsConsentManager.sharedInstance.canRequestAds) {
124-
[self loadBannerAd];
125-
}
126-
}
127-
completion:nil];
128-
}
129-
130118
- (void)startGoogleMobileAdsSDK {
131119
static dispatch_once_t onceToken;
132120
dispatch_once(&onceToken, ^{

Objective-C/advanced/APIDemo/APIDemo/Snippets/BannerSnippets.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ - (void)viewDidLoad {
3030
[self createBannerViewProgrammatically];
3131
}
3232

33+
// [START handle_orientation_changes]
34+
- (void)viewWillTransitionToSize:(CGSize)size
35+
withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
36+
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
37+
// Load a new ad for the new orientation.
38+
} completion:nil];
39+
}
40+
// [END handle_orientation_changes]
41+
3342
- (void)createBannerViewProgrammatically {
3443
// [START create_banner_view]
3544
// Initialize the GADBannerView.

Swift/admanager/AdManagerBannerExample/AdManagerBannerExample/ViewController.swift

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,6 @@ class ViewController: UIViewController, BannerViewDelegate {
5858
}
5959
}
6060

61-
override func viewWillTransition(
62-
to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator
63-
) {
64-
coordinator.animate(alongsideTransition: { _ in
65-
if GoogleMobileAdsConsentManager.shared.canRequestAds {
66-
self.loadBannerAd()
67-
}
68-
})
69-
}
70-
7161
private func startGoogleMobileAdsSDK() {
7262
DispatchQueue.main.async {
7363
guard !self.isMobileAdsStartCalled else { return }

Swift/admob/BannerExample/BannerExample/ViewController.swift

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,6 @@ class ViewController: UIViewController, BannerViewDelegate {
5757
}
5858
}
5959

60-
override func viewWillTransition(
61-
to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator
62-
) {
63-
coordinator.animate(alongsideTransition: { _ in
64-
if GoogleMobileAdsConsentManager.shared.canRequestAds {
65-
self.loadBannerAd()
66-
}
67-
})
68-
}
69-
7060
/// Handle changes to user consent.
7161
@IBAction func privacySettingsTapped(_ sender: UIBarButtonItem) {
7262
Task {

Swift/advanced/APIDemo/APIDemo/Snippets/BannerSnippets.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ private class BannerSnippets: UIViewController {
2525
createBannerViewProgrammatically()
2626
}
2727

28+
// [START handle_orientation_changes]
29+
override func viewWillTransition(
30+
to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator
31+
) {
32+
coordinator.animate(alongsideTransition: { _ in
33+
// Load a new ad for the new orientation.
34+
})
35+
}
36+
// [END handle_orientation_changes]
37+
2838
private func createBannerViewProgrammatically() {
2939
// [START create_banner_view]
3040
// Initialize the BannerView.

0 commit comments

Comments
 (0)