我使用Firebase实施了测试adMob:
override func viewDidLoad() {
super.viewDidLoad()
interstitial = createAndLoadInterstitial()
interstitial.delegate = self
....}
func createAndLoadInterstitial() -> GADInterstitial {
var interstitial = GADInterstitial(adUnitID: "testVideo")
interstitial.delegate = self
interstitial.load(GADRequest())
return interstitial
}
func interstitialWillDismissScreen(_ ad: GADInterstitial) {
print("interstitialWillDismissScreen")
UserDefaults.standard.set(false, forKey: "adWasShowing")
}
func interstitialDidDismissScreen(_ ad: GADInterstitial) {
if ... {
...
}
interstitial = createAndLoadInterstitial()
print("interstitialDidDismissScreen")
}
问题是当我收到广告(5秒视频)并将应用程序带到后台再到前景时
interstitialWillDismissScreen和interstitialDidDismissScreen
会自动调用,从而导致关闭广告。我想很多用户都会使用这种漏洞来保留视频。关于如何解决这个问题的任何想法?
我尝试在“interstitialWillPresentScreen”中的UserDefaults中设置一个bool并在“applicationWillEnterForeground”处查看,但我不喜欢这个想法,并且还没有加载插页式广告请求(必须为每个广告重新创建interstitialRequest) )。