加载屏幕后 Admob 不显示插页式广告,在某些情况下只显示一次
Admob not displaying interstitials after screen is loaded, only one time in some cases
在我的应用程序中加载新屏幕后,我正在使用 admob 8.0.0 显示插页式广告,但出了点问题,因为正在调用当前函数,但插页式广告未显示。
如果我尝试用一个调用当前函数的按钮来显示它们,那么它只会显示一次,只有在我第一次按下按钮时。如果我多次按下它,将不再调用插页式广告,并且代码将执行当前函数的行。正在调用 None 个委托事件。
谁能给我解释一下哪里出了问题?
我正在以这种方式加载插页式广告:
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.")
}
}
我在加载新屏幕后或按这种方式按下插页式按钮时显示它们:
override func showInterstitial(viewController: SectionViewController?) {
guard loaded, let controller = viewController else {
return
}
gadInterstitial?.present(fromRootViewController: controller)
logger.debug("Displaying interstitial view")
}
您在调用 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")
}
在我的应用程序中加载新屏幕后,我正在使用 admob 8.0.0 显示插页式广告,但出了点问题,因为正在调用当前函数,但插页式广告未显示。
如果我尝试用一个调用当前函数的按钮来显示它们,那么它只会显示一次,只有在我第一次按下按钮时。如果我多次按下它,将不再调用插页式广告,并且代码将执行当前函数的行。正在调用 None 个委托事件。
谁能给我解释一下哪里出了问题?
我正在以这种方式加载插页式广告:
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.")
}
}
我在加载新屏幕后或按这种方式按下插页式按钮时显示它们:
override func showInterstitial(viewController: SectionViewController?) {
guard loaded, let controller = viewController else {
return
}
gadInterstitial?.present(fromRootViewController: controller)
logger.debug("Displaying interstitial view")
}
您在调用 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") }