Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions GADManager/GADManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -452,11 +452,11 @@ public class GADManager<E : RawRepresentable> : NSObject, GoogleMobileAds.FullSc
}*/

//ignore if alert is being presented
/*if let alert = UIApplication.shared.keyWindow?.rootViewController?.presentedViewController as? UIAlertController{
/*if let alert = UIApplication.shared.keyRootViewController?.presentedViewController as? UIAlertController{
alert.dismiss(animated: false, completion: nil);
}*/

guard !(UIApplication.shared.keyWindow?.rootViewController?.presentedViewController is UIAlertController) else{
guard !(UIApplication.shared.keyRootViewController?.presentedViewController is UIAlertController) else{
//alert.dismiss(animated: false, completion: nil);
//self.fullAd = nil;
completion?(unit, self.adObjects[unit], false);
Expand Down
27 changes: 25 additions & 2 deletions GADManager/extensions/UIApplication+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import UIKit

extension UIApplication{

/**
os compatible for function to open url
*/
Expand All @@ -28,7 +28,7 @@ extension UIApplication{
self.openURL(url);
}
}

/**
Opens Settings App page for this app
- parameter completion: block to call after opening Settings App has been completed
Expand All @@ -38,3 +38,26 @@ extension UIApplication{
self.openCompatible(url_settings!, options: [:], completionHandler: completion)
}
}

/// Private extension to safely access the root view controller in iOS 13+ scene-based apps
private extension UIApplication {
/// Returns the root view controller of the key window in the active scene.
/// For multi-scene apps, prioritizes the foreground active scene with fallback logic.
/// - Returns: The root view controller, or nil if no valid scene/window is found.
var keyRootViewController: UIViewController? {
// First, try to get the foreground active scene (ideal for multi-scene apps)
if let windowScene = self.connectedScenes
.first(where: { $0.activationState == .foregroundActive }) as? UIWindowScene {
return windowScene.windows.first(where: { $0.isKeyWindow })?.rootViewController
}

// Fallback: try any connected scene if no foreground active scene is available
guard let windowScene = self.connectedScenes
.compactMap({ $0 as? UIWindowScene })
.first else {
return nil
}

return windowScene.windows.first(where: { $0.isKeyWindow })?.rootViewController
}
}
Loading