diff --git a/Objective-C/admanager/AdManagerAppOpenExample/AdManagerAppOpenExample/AppDelegate.m b/Objective-C/admanager/AdManagerAppOpenExample/AdManagerAppOpenExample/AppDelegate.m index ec19052a..4eb37b7c 100644 --- a/Objective-C/admanager/AdManagerAppOpenExample/AdManagerAppOpenExample/AppDelegate.m +++ b/Objective-C/admanager/AdManagerAppOpenExample/AdManagerAppOpenExample/AppDelegate.m @@ -24,15 +24,8 @@ - (BOOL)application:(UIApplication *)application } - (void) applicationDidBecomeActive:(UIApplication *)application { - NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF.isKeyWindow == YES"]; - UIWindow *keyWindow = [[application.windows filteredArrayUsingPredicate:predicate] firstObject]; - UIViewController *rootViewController = keyWindow.rootViewController; - // Do not show app open ad if the current view controller is SplashViewController. - if (!rootViewController || - [rootViewController isKindOfClass:[SplashViewController class]]) { - return; - } - [AppOpenAdManager.sharedInstance showAdIfAvailable:rootViewController]; + // Show the app open ad when the app is foregrounded. + [AppOpenAdManager.sharedInstance showAdIfAvailable]; } @end diff --git a/Objective-C/admanager/AdManagerAppOpenExample/AdManagerAppOpenExample/AppOpenAdManager.h b/Objective-C/admanager/AdManagerAppOpenExample/AdManagerAppOpenExample/AppOpenAdManager.h index a98a2a7e..53672259 100644 --- a/Objective-C/admanager/AdManagerAppOpenExample/AdManagerAppOpenExample/AppOpenAdManager.h +++ b/Objective-C/admanager/AdManagerAppOpenExample/AdManagerAppOpenExample/AppOpenAdManager.h @@ -29,6 +29,6 @@ + (nonnull AppOpenAdManager *)sharedInstance; - (void)loadAd; -- (void)showAdIfAvailable:(nonnull UIViewController*)viewController; +- (void)showAdIfAvailable; @end diff --git a/Objective-C/admanager/AdManagerAppOpenExample/AdManagerAppOpenExample/AppOpenAdManager.m b/Objective-C/admanager/AdManagerAppOpenExample/AdManagerAppOpenExample/AppOpenAdManager.m index 30f37b0b..4ba9ae61 100644 --- a/Objective-C/admanager/AdManagerAppOpenExample/AdManagerAppOpenExample/AppOpenAdManager.m +++ b/Objective-C/admanager/AdManagerAppOpenExample/AdManagerAppOpenExample/AppOpenAdManager.m @@ -95,7 +95,7 @@ - (void)loadAd { }]; } -- (void)showAdIfAvailable:(nonnull UIViewController *)viewController { +- (void)showAdIfAvailable { // If the app open ad is already showing, do not show the ad again. if (_isShowingAd) { NSLog(@"App open ad is already showing."); @@ -114,7 +114,7 @@ - (void)showAdIfAvailable:(nonnull UIViewController *)viewController { } NSLog(@"App open ad will be displayed."); _isShowingAd = YES; - [_appOpenAd presentFromRootViewController:viewController]; + [_appOpenAd presentFromRootViewController:nil]; } #pragma mark - GADFullScreenContentDelegate diff --git a/Objective-C/admanager/AdManagerAppOpenExample/AdManagerAppOpenExample/SplashViewController.m b/Objective-C/admanager/AdManagerAppOpenExample/AdManagerAppOpenExample/SplashViewController.m index 9056ee59..172c3401 100644 --- a/Objective-C/admanager/AdManagerAppOpenExample/AdManagerAppOpenExample/SplashViewController.m +++ b/Objective-C/admanager/AdManagerAppOpenExample/AdManagerAppOpenExample/SplashViewController.m @@ -91,7 +91,7 @@ - (void)decrementCounter { [_countdownTimer invalidate]; _countdownTimer = nil; - [AppOpenAdManager.sharedInstance showAdIfAvailable:self]; + [AppOpenAdManager.sharedInstance showAdIfAvailable]; } - (void)startGoogleMobileAdsSDK { diff --git a/Objective-C/admob/AppOpenExample/AppOpenExample/AppDelegate.m b/Objective-C/admob/AppOpenExample/AppOpenExample/AppDelegate.m index ec19052a..4eb37b7c 100644 --- a/Objective-C/admob/AppOpenExample/AppOpenExample/AppDelegate.m +++ b/Objective-C/admob/AppOpenExample/AppOpenExample/AppDelegate.m @@ -24,15 +24,8 @@ - (BOOL)application:(UIApplication *)application } - (void) applicationDidBecomeActive:(UIApplication *)application { - NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF.isKeyWindow == YES"]; - UIWindow *keyWindow = [[application.windows filteredArrayUsingPredicate:predicate] firstObject]; - UIViewController *rootViewController = keyWindow.rootViewController; - // Do not show app open ad if the current view controller is SplashViewController. - if (!rootViewController || - [rootViewController isKindOfClass:[SplashViewController class]]) { - return; - } - [AppOpenAdManager.sharedInstance showAdIfAvailable:rootViewController]; + // Show the app open ad when the app is foregrounded. + [AppOpenAdManager.sharedInstance showAdIfAvailable]; } @end diff --git a/Objective-C/admob/AppOpenExample/AppOpenExample/AppOpenAdManager.h b/Objective-C/admob/AppOpenExample/AppOpenExample/AppOpenAdManager.h index a98a2a7e..53672259 100644 --- a/Objective-C/admob/AppOpenExample/AppOpenExample/AppOpenAdManager.h +++ b/Objective-C/admob/AppOpenExample/AppOpenExample/AppOpenAdManager.h @@ -29,6 +29,6 @@ + (nonnull AppOpenAdManager *)sharedInstance; - (void)loadAd; -- (void)showAdIfAvailable:(nonnull UIViewController*)viewController; +- (void)showAdIfAvailable; @end diff --git a/Objective-C/admob/AppOpenExample/AppOpenExample/AppOpenAdManager.m b/Objective-C/admob/AppOpenExample/AppOpenExample/AppOpenAdManager.m index 7d32bd35..ccc73014 100644 --- a/Objective-C/admob/AppOpenExample/AppOpenExample/AppOpenAdManager.m +++ b/Objective-C/admob/AppOpenExample/AppOpenExample/AppOpenAdManager.m @@ -95,7 +95,7 @@ - (void)loadAd { }]; } -- (void)showAdIfAvailable:(nonnull UIViewController *)viewController { +- (void)showAdIfAvailable { // If the app open ad is already showing, do not show the ad again. if (_isShowingAd) { NSLog(@"App open ad is already showing."); @@ -114,7 +114,7 @@ - (void)showAdIfAvailable:(nonnull UIViewController *)viewController { } NSLog(@"App open ad will be displayed."); _isShowingAd = YES; - [_appOpenAd presentFromRootViewController:viewController]; + [_appOpenAd presentFromRootViewController:nil]; } #pragma mark - GADFullScreenContentDelegate diff --git a/Objective-C/admob/AppOpenExample/AppOpenExample/SplashViewController.m b/Objective-C/admob/AppOpenExample/AppOpenExample/SplashViewController.m index 9056ee59..172c3401 100644 --- a/Objective-C/admob/AppOpenExample/AppOpenExample/SplashViewController.m +++ b/Objective-C/admob/AppOpenExample/AppOpenExample/SplashViewController.m @@ -91,7 +91,7 @@ - (void)decrementCounter { [_countdownTimer invalidate]; _countdownTimer = nil; - [AppOpenAdManager.sharedInstance showAdIfAvailable:self]; + [AppOpenAdManager.sharedInstance showAdIfAvailable]; } - (void)startGoogleMobileAdsSDK { diff --git a/Swift/admanager/AdManagerAppOpenExample/AdManagerAppOpenExample/AppDelegate.swift b/Swift/admanager/AdManagerAppOpenExample/AdManagerAppOpenExample/AppDelegate.swift index 08f36d44..9febea54 100644 --- a/Swift/admanager/AdManagerAppOpenExample/AdManagerAppOpenExample/AppDelegate.swift +++ b/Swift/admanager/AdManagerAppOpenExample/AdManagerAppOpenExample/AppDelegate.swift @@ -29,14 +29,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { } func applicationDidBecomeActive(_ application: UIApplication) { - let rootViewController = application.windows.first( - where: { $0.isKeyWindow })?.rootViewController - if let rootViewController = rootViewController { - // Do not show app open ad if the current view controller is SplashViewController. - if rootViewController is SplashViewController { - return - } - AppOpenAdManager.shared.showAdIfAvailable(viewController: rootViewController) - } + // Show the app open ad when the app is foregrounded. + AppOpenAdManager.shared.showAdIfAvailable() } } diff --git a/Swift/admanager/AdManagerAppOpenExample/AdManagerAppOpenExample/AppOpenAdManager.swift b/Swift/admanager/AdManagerAppOpenExample/AdManagerAppOpenExample/AppOpenAdManager.swift index b5ed24ca..8f2efdb3 100644 --- a/Swift/admanager/AdManagerAppOpenExample/AdManagerAppOpenExample/AppOpenAdManager.swift +++ b/Swift/admanager/AdManagerAppOpenExample/AdManagerAppOpenExample/AppOpenAdManager.swift @@ -81,7 +81,7 @@ class AppOpenAdManager: NSObject { isLoadingAd = false } - func showAdIfAvailable(viewController: UIViewController) { + func showAdIfAvailable() { // If the app open ad is already showing, do not show the ad again. if isShowingAd { print("App open ad is already showing.") @@ -103,7 +103,7 @@ class AppOpenAdManager: NSObject { if let ad = appOpenAd { print("App open ad will be displayed.") isShowingAd = true - ad.present(fromRootViewController: viewController) + ad.present(fromRootViewController: nil) } } } diff --git a/Swift/admanager/AdManagerAppOpenExample/AdManagerAppOpenExample/SplashViewController.swift b/Swift/admanager/AdManagerAppOpenExample/AdManagerAppOpenExample/SplashViewController.swift index 1cb9c4d1..01c435f2 100644 --- a/Swift/admanager/AdManagerAppOpenExample/AdManagerAppOpenExample/SplashViewController.swift +++ b/Swift/admanager/AdManagerAppOpenExample/AdManagerAppOpenExample/SplashViewController.swift @@ -68,7 +68,7 @@ class SplashViewController: UIViewController, AppOpenAdManagerDelegate { splashScreenLabel.text = "Done." countdownTimer?.invalidate() - AppOpenAdManager.shared.showAdIfAvailable(viewController: self) + AppOpenAdManager.shared.showAdIfAvailable() } private func startGoogleMobileAdsSDK() { diff --git a/Swift/admob/AppOpenExample/AppOpenExample/AppDelegate.swift b/Swift/admob/AppOpenExample/AppOpenExample/AppDelegate.swift index 08f36d44..9febea54 100644 --- a/Swift/admob/AppOpenExample/AppOpenExample/AppDelegate.swift +++ b/Swift/admob/AppOpenExample/AppOpenExample/AppDelegate.swift @@ -29,14 +29,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { } func applicationDidBecomeActive(_ application: UIApplication) { - let rootViewController = application.windows.first( - where: { $0.isKeyWindow })?.rootViewController - if let rootViewController = rootViewController { - // Do not show app open ad if the current view controller is SplashViewController. - if rootViewController is SplashViewController { - return - } - AppOpenAdManager.shared.showAdIfAvailable(viewController: rootViewController) - } + // Show the app open ad when the app is foregrounded. + AppOpenAdManager.shared.showAdIfAvailable() } } diff --git a/Swift/admob/AppOpenExample/AppOpenExample/AppOpenAdManager.swift b/Swift/admob/AppOpenExample/AppOpenExample/AppOpenAdManager.swift index d001b0cf..9df041df 100644 --- a/Swift/admob/AppOpenExample/AppOpenExample/AppOpenAdManager.swift +++ b/Swift/admob/AppOpenExample/AppOpenExample/AppOpenAdManager.swift @@ -81,7 +81,7 @@ class AppOpenAdManager: NSObject { isLoadingAd = false } - func showAdIfAvailable(viewController: UIViewController) { + func showAdIfAvailable() { // If the app open ad is already showing, do not show the ad again. if isShowingAd { print("App open ad is already showing.") @@ -103,7 +103,7 @@ class AppOpenAdManager: NSObject { if let ad = appOpenAd { print("App open ad will be displayed.") isShowingAd = true - ad.present(fromRootViewController: viewController) + ad.present(fromRootViewController: nil) } } } diff --git a/Swift/admob/AppOpenExample/AppOpenExample/SplashViewController.swift b/Swift/admob/AppOpenExample/AppOpenExample/SplashViewController.swift index 1cb9c4d1..01c435f2 100644 --- a/Swift/admob/AppOpenExample/AppOpenExample/SplashViewController.swift +++ b/Swift/admob/AppOpenExample/AppOpenExample/SplashViewController.swift @@ -68,7 +68,7 @@ class SplashViewController: UIViewController, AppOpenAdManagerDelegate { splashScreenLabel.text = "Done." countdownTimer?.invalidate() - AppOpenAdManager.shared.showAdIfAvailable(viewController: self) + AppOpenAdManager.shared.showAdIfAvailable() } private func startGoogleMobileAdsSDK() {