我有GADInterstitial
class AdsManager {
let adsAppId = MY_ID
let fullScreenAdUnitId = MY_ID
static let manager: AdsManager = AdsManager()
private var interstitial: GADInterstitial!
private init () {
createAndLoadInterstitial()
}
func presentInterstitial(fromViewController viewController: UIViewController) {
if interstitial.isReady {
interstitial.present(fromRootViewController: viewController)
}
else {
print("Interstitial is not ready")
}
createAndLoadInterstitial()
}
private func createAndLoadInterstitial() {
//TODO: replace test ad unit id with production
interstitial = GADInterstitial(adUnitID: MY_ID)
interstitial.load(GADRequest())
}
}
我展示了这样的广告:
func touchedButton(_ sender: UIButton) {
AdsManager.manager.presentInterstitial(fromViewController: self)
}
Everythink工作并且看起来很好但是当我调试时我发现了一些奇怪的东西:
同一视图的四个实例。有谁知道它好吗?或许我在AdsManager
犯了错误?也许Firebase实施错误?
答案 0 :(得分:2)
GADUIKitWebView
的数量取决于所呈现的广告类型。视频,图片和文字广告都将采用不同的布局。根据使用的内存量,我认为它是正确的。
查看交互式GADInterstitial
广告的层次结构:
除此之外,您的实施确实存在问题。你的问题在于这个功能:
func presentInterstitial(fromViewController viewController: UIViewController) {
if interstitial.isReady {
interstitial.present(fromRootViewController: viewController)
}
else {
print("Interstitial is not ready")
}
createAndLoadInterstitial() // PROBLEM
}
您应该将createAndLoadInterstitial()
移至else
,以便在实际需要时只加载另一个GADInterstitial
。例如:
func presentInterstitial(fromViewController viewController: UIViewController) {
if interstitial.isReady {
interstitial.present(fromRootViewController: viewController)
}
else {
print("Interstitial is not ready")
createAndLoadInterstitial()
}
}
除此之外,您应该实施GADInterstitial
delegate methods并仅在其解除屏幕后加载另一个GADInterstitial
。例如:
/// Called just after dismissing an interstitial and it has animated off the screen.
func interstitialDidDismissScreen(_ ad: GADInterstitial) {
print("interstitialDidDismissScreen")
createAndLoadInterstitial()
}