激励广告偶尔会延伸到 iPhone 显示屏的边缘并忽略安全区域。这会导致关闭按钮呈现在与控制中心触发器相同的位置,从而无法点击关闭按钮。 (请参考截图)。
这是用于显示激励广告的代码片段 -
extension UIApplication {
var keyWindow: UIWindow? {
connectedScenes
.compactMap {
$0 as? UIWindowScene
}
.flatMap {
$0.windows
}
.first {
$0.isKeyWindow
}
}
public var rootViewController: UIViewController? {
guard let keyWindow = UIApplication.shared.keyWindow, let rootViewController = keyWindow.rootViewController else {
return nil
}
return rootViewController
}
public func topViewController(controller: UIViewController? = UIApplication.shared.rootViewController) -> UIViewController? {
if controller == nil {
return topViewController(controller: rootViewController)
}
if let navigationController = controller as? UINavigationController {
return topViewController(controller: navigationController.visibleViewController)
}
if let tabController = controller as? UITabBarController {
if let selectedViewController = tabController.selectedViewController {
return topViewController(controller: selectedViewController)
}
}
if let presentedViewController = controller?.presentedViewController {
return topViewController(controller: presentedViewController)
}
return controller
}
}
guard let currentUiViewController = UIApplication.shared.topViewController() else { return }
rewardedAd.present(fromRootViewController: currentUiViewController) {
let reward = rewardedAd.adReward
self.rewardAdPlaybackCallbacks?.onUserEarnedReward(rewardAdHandle: self.currentRewardAdHandle!)
}
我还尝试更改
currentUiViewController
的安全区域行为,并尝试了两种方法,首先,忽略安全区域,其次,尊重安全区域。两种情况下都会出现此问题。
有办法解决或解决这个问题吗?任何提示或建议都会非常有帮助。预先感谢!
我也遇到同样的问题
如果您有解决方案,请分享。