如何解决加载屏幕后 Admob 不显示插页式广告,在某些情况下仅显示一次
在我的应用程序中加载新屏幕后,我正在使用 admob 8.0.0 显示插页式广告,但出了点问题,因为正在调用当前函数但未显示插页式广告。
如果我尝试使用调用当前函数的按钮来显示它们,那么它只会显示一次,仅在我第一次按下按钮时显示。如果我按更多次,则不会调用更多的插页式广告,并且代码正在执行当前函数的行。没有调用任何 RUN pip install cx-Oracle==7.0.0 pandas==1.1.2
委托事件。
谁能解释一下哪里出了问题?
我正在以这种方式加载插页式广告:
GADFullScreenContentDelegate
我在新屏幕加载后或以这种方式按下插页式按钮时显示它们:
self.gadInterstitial?.fullScreenContentDelegate = self
let request = GADRequest()
GADInterstitialAd.load(withAdUnitID:self.adId,request: request,completionHandler: { [self] ad,error in
if let error = error {
logger.error(error.localizedDescription)
return
}
gadInterstitial = ad
logger.debug("Loaded Ad Mob interstitial view")
loaded = true
}
)
extension AdMobAdEntity: GADFullScreenContentDelegate {
/// Tells the delegate that the ad failed to present full screen content.
func ad(_ ad: GADFullScreenPresentingAd,didFailToPresentFullScreenContentWithError error: Error) {
print("Ad did fail to present full screen content.")
}
/// Tells the delegate that the ad presented full screen content.
func adDidPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) {
print("Ad did present full screen content.")
}
/// Tells the delegate that the ad dismissed full screen content.
func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) {
print("Ad did dismiss full screen content.")
}
}
解决方法
您在调用 loadInterstitial() 函数后关闭广告
func loadInterstitial() {
let request = GADRequest()
GADInterstitialAd.load(
withAdUnitID: self.adId,request: request
) { (ad,error) in
if let error = error {
logger.error(error.localizedDescription)
return
}
self.gadInterstitial = ad
logger.debug("Loaded Ad Mob interstitial view")
loaded = true
self.gadInterstitial?.fullScreenContentDelegate = self
}
}
func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) {
print("Ad did dismiss full screen content.")
loaded = false
loadInterstitial()
}
override func showInterstitial(viewController: SectionViewController?) {
guard loaded,let controller = viewController else {
loadInterstitial()
return
}
gadInterstitial?.present(fromRootViewController: controller)
logger.debug("Displaying interstitial view")
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。