我有一个WebKit应用,并且一直在尝试让AdMob在计时器上展示插页式广告,以便每隔x秒显示一次。我在这里搜索,发现了一个旧的解决方案,但是它似乎不再起作用。广告只会展示一次,而不会再次展示。使它每隔x秒显示一次的任何帮助都会很棒。
这就是我得到的:
var interstital: GADInterstitial!
override func viewDidLoad() {
super.viewDidLoad()
interstital = GADInterstitial(adUnitID:
"ca-app-pub-3940256099942544/1033173712")
let request = GADRequest()
interstital.load(request)
let randomTime = Double(arc4random() + 15).truncatingRemainder(dividingBy: 20.0)
Timer.scheduledTimer(timeInterval: randomTime, target: self, selector: #selector(ViewController.CreateAd), userInfo: nil, repeats: true)
}
@objc func CreateAd() -> GADInterstitial {
if (interstital.isReady) {
interstital.present(fromRootViewController: self)
let randomTime = Double(arc4random() + 180).truncatingRemainder(dividingBy: 200.0)
Timer.scheduledTimer(timeInterval: randomTime, target: self, selector: #selector(ViewController.CreateAd), userInfo: nil, repeats: true)
}
return interstital
}