问题描述
我正在使用一个带有三个按钮的ViewController创建Ann应用程序,该按钮会导致其他三个ViewController ...
我希望当用户点击按钮时展示插页式广告。广告完成后,将显示视图控制器,并且当用户关闭视图控制器并转到根视图控制器并尝试打开另一个视图控制器时,广告将出现,然后显示视图控制器。
我下面的代码使广告出现,但完成后不要打开目标视图控制器。
import UIKit
import AVKit
import GoogleMobileAds
class ViewController: UIViewController {
private var interstitialad : GADInterstitial!
override func viewDidLoad() {
super.viewDidLoad()
self.interstitialad = createAd()
}
@IBAction func news(_ sender: Any) {
if interstitialad?.isReady == true {
interstitialad?.present(fromRootViewController: self)
}
}
@IBAction func table(_ sender: Any) {
if interstitialad?.isReady == true {
interstitialad?.present(fromRootViewController: self)
}
}
@IBAction func channels(_ sender: Any) {
if interstitialad?.isReady == true {
interstitialad?.present(fromRootViewController: self)
}
}
private func createAd() ->GADInterstitial {
let ad = GADInterstitial(adUnitID: "ca-app-pub-3940256099942544/4411468910")
ad.delegate = self
ad.load(GADRequest())
return ad
}
}
extension ViewController: GADInterstitialDelegate{
func interstitialDidDismissScreen(_ ad: GADInterstitial) {
interstitialad = createAd()
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)