我正在尝试将插页式广告添加到我的应用中。我有 6 个连续的 View Controller 。我在 VC#5 上有 3 个按钮。其中两个是 VC#1 和 VC#3 的展开转场。第三个按钮通向 VC#6。我希望每个按钮都能触发添加。我可以将广告添加到带有正向序列的第三个按钮。但我正在努力解开转场按钮。广告仅展示一秒钟,然后放松继续。
var interstitial: GADInterstitial!
override func viewDidLoad() {
super.viewDidLoad()
interstitial = createAndLoadInterstitial()
}
func createAndLoadInterstitial() -> GADInterstitial {
let interstitial = GADInterstitial(adUnitID: "ca-app-pub-3940256099942544/4411468910")
interstitial.delegate = self
interstitial.load(GADRequest())
return interstitial
}
func interstitialDidDismissScreen(_ ad: GADInterstitial) {
interstitial = createAndLoadInterstitial()
}
我尝试使用带标识符的展开转场作为一个按钮,并使用带按钮的直接转场作为第二个按钮。
@IBAction func againButtonPressed(_ sender: UIButton) {
if interstitial.isReady {
interstitial.present(fromRootViewController: self)
} else {
print("Ad wasn't ready")
}
performSegue(withIdentifier: "backToInstruction", sender: self)
}
@IBAction func endButtonPressed(_ sender: UIButton) {
if interstitial.isReady {
interstitial.present(fromRootViewController: self)
} else {
print("Ad wasn't ready")
}
}
我尝试在 interstitialDidDismissScreen 函数中使用 PerformSegue。还可以,add被解散后会触发segue,但是As的传球被按下后需要10秒才能进入VC,这不是最好的体验。 所以,我不知道还能尝试什么......
最佳答案
您不应在显示“添加”后立即触发“performSegue”。相反,您需要将其推迟到“添加”被取消为止。为此,您需要将 Segue 代码移至 interstitialDidDismissScreen 回调。像这样,
func interstitialDidDismissScreen(_ ad: GADInterstitial) {
if isAgainButtonPressed {
performSegue(withIdentifier: "backToInstruction", sender: self)
return
}
interstitial = createAndLoadInterstitial()
}
并且您在 AgainButtonPresed 方法中将 isAgainButtonPressed 设置为 true。
关于ios - 插页式广告立即隐藏并展开转场,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57945997/