Finally found the issue and fixed like following.
extension UIApplication {
var keyWindow: UIWindow? {
// Get connected scenes
return UIApplication.shared.connectedScenes
// Keep only active scenes, onscreen and visible to the user
.filter { $0.activationState == .foregroundActive }
// Keep only the first `UIWindowScene`
.first(where: { $0 is UIWindowScene })
// Get its associated windows
.flatMap({ $0 as? UIWindowScene })?.windows
// Finally, keep only the key window
.first(where: \.isKeyWindow)
}
}
UIApplication extension code from https://stackoverflow.com/a/68989580/215939
func loadBannerAd() {
let frame = view.frame.inset(by: view.safeAreaInsets)
let viewWidth = frame.size.width
//Updates the BannerView size relative to the current safe area of device (This creates the adaptive banner)
bannerView.adSize = GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(viewWidth)
let request = GADRequest()
if let scene = UIApplication.shared.keyWindow?.rootViewController?.view.window?.windowScene {
request.scene = scene
}
bannerView.load(request)
}
The main problem is
I need to set the scene in request
let request = GADRequest()
if let scene = UIApplication.shared.keyWindow?.rootViewController?.view.window?.windowScene {
request.scene = scene
}
After that , working fine on the iPad.